Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Guide: Creating a cloud build bot in Microsoft Teams

Discussion in 'Unity Build Automation' started by tonemcbride, Apr 17, 2019.

  1. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,083
    Hi,

    I recently wrote a guide that creates a notification in Microsoft Teams when a Cloud Build has been completed (see this link for more info: https://forum.unity.com/threads/guide-connecting-integration-webhooks-to-microsoft-teams.587530/)

    I also created a 'build bot' so I thought I'd add a tutorial here on how I did it. It's a bot that you can talk to in Microsoft Teams and ask it to start cloud builds for you (and also stop them and list current builds). I realise you can do this from the Cloud Build website but it's nice to have everything available from within Teams so all team members can access it - it's also interesting to do if you like automating everything like me.

    As with the other guide, you will need to have access to a server that can run PHP scripts and also have PHP CURL active.

    Here are the steps to set things up:

    1) In Teams click the ellipsis beside the team that you want the bot to be available from (the bot only works from Team conversations and not general chat).

    2) Select 'Manage Team'

    upload_2019-4-17_15-10-3.png

    3) Select 'Apps' tab

    upload_2019-4-17_15-11-14.png

    and then click 'Create an outgoing webhook' at the bottom right of that panel.


    4 to 7) Fill in the information for the bot in the panel that appears:

    upload_2019-4-17_15-12-6.png

    You can name it anything but a single word name is easier when referencing it in Teams. The URL is the location of the attached 'buildbot.php' file on your server.

    8) Next we need to get the 'API Key' for the cloud build so the PHP file can be allowed to start and stop cloud builds. You can get that from https://developer.cloud.unity3d.com/preferences/ (it's at the bottom of the page)

    9) Edit the buildbot.php file on your server (I use nano but any editor is fine)

    upload_2019-4-17_15-15-39.png

    As you can see it's just an array of possible build targets. If you only have one target make sure to remove the commas at the end of each array entry. Each entry has the following info that you can edit:

    'name' - This can be anything you like and is just a way of referencing a particular target from Teams
    'api_key' - This is the API key of the cloud build owner. You can use different api keys if you have multiple companies that you work with

    'orgid' / 'projectid' / 'buildtargetid' - To find this info go to the cloud build dashboard and view a completed build. In the URL you should be able to get the info:

    For example:

    https://developer.cloud.unity3d.com/build/orgs/orgid/projects/projectid/buildtargets/buildtargetid/builds/13/log/compact/

    Once that's all done you can just go into a Teams channel and do:

    @BuildBot start mobile

    or

    @BuildBot list mobile
    @BuildBot stop mobile

    The second parameter is the 'name' of the target so you can use it control multiple builds.
     

    Attached Files:

    JoshW_3, mgear and victorw like this.
  2. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,083
    p.s. I'd ran out of attachments in the initial message so here's a pic of it working in Teams:

    upload_2019-4-17_15-31-27.png
     
    victorw likes this.