Azure DevOps (VSTS)

Learn how to connect Blue Canvas with Azure DevOps (VSTS - Visual Studio Team Services)

It can be useful to get your Salesforce code and metadata into Azure DevOps (Visual Studio Team Services). Blue Canvas makes it easy to keep your declarative and configuration changes synced directly between Salesforce and VSTS.

3104

👍

Before you start, familiarize yourself with Git and how to clone your Blue Canvas repository to make an external copy.

Initial import

Start by creating a new project in Azure DevOps.

  • Click Create project. Enter a project name and click Create.
3104

The project starts out with an empty repository. Run an initial import to populate it.

  • Go to Repos. Click Import a repositoryImport.
  • Select Git as the source type
  • Copy and paste https://git.bluecanvas.io/... into the Clone URL
  • Select Requires authorization
  • Enter your Blue Canvas username and password
  • Click Import
  • Sit back and wait for the import to finish.
1118

You now have a snapshot copy of Blue Canvas in Azure DevOps. Well done!

Note: The initial import into Azure DevOps doesn't copy binary files (e.g. Documents, StaticResources) because they are stored in Git LFS. Follow the next steps to copy those files.

Prepare security settings

Azure Pipelines uses a dynamic security model to control who can read or write to the repository. Before you can configure an automated importer pipeline, you need to add explicit permissions to allow $(System.AccessToken) to write to the repository.

  • Go to Project settingsReposRepositories
  • Stay on the page titled All Repositories and go to Permissions
  • In the search field, enter Project Collection Build Service
    • Match the permissions to the screenshot below.
  • Select UsersProject Build Service
    • Match the permissions to the screenshot below.
  • Select GroupsProject Collection Build Service Accounts
    • Match the permissions to the screenshot below.
3104

Automatically import changes

You are ready to set up an automated build script to periodically pull new changes.

  • Go to PipelinesBuilds and click New pipeline
  • Click Other Git when asked to select the source
  • Click Add connection
  • Copy and paste https://git.bluecanvas.io/... into the Git repository URL
  • Enter your Blue Canvas username and password and click OK.
  • Enter the name of any Blue Canvas branch in Default branch for manual and scheduled builds, for example prod, and click Continue.
3104
  • When asked to select a template, click Empty job

Now you need to adjust the configuration and add a script.

  • Select Get sources. At the bottom of the screen enable Checkout files from LFS.
3104
  • Select Agent job 1.
  • For Agent pool choose Hosted Ubuntu 1604.
  • At the bottom of the page under Additional options enable Allow scripts to access the OAuth token.
3104
  • Click the blue + button to add a new task. Search for Command line and add it.
  • Select the new Command Line Script entry and paste the script snippet below.
  • Replace the <AZURE_CLONE_URL> placeholders with the Azure Git clone URL. You can find the URL in Azure DevOps under ReposFilesCloneHTTPS.
set -ex

export AZURE_CLONE_URL="<AZURE_CLONE_URL>"

git show-ref
git for-each-ref --format='%(refname:lstrip=3)' 'refs/remotes/origin/*' | while read -r name; do git branch --track $name origin/$name; done
git branch -l

git lfs fetch --all
git remote remove origin

git remote add azure $AZURE_CLONE_URL
git config http.$AZURE_CLONE_URL.extraHeader "Authorization: Bearer $SYSTEM_ACCESSTOKEN"
git config lfs.$AZURE_CLONE_URL.git/info/lfs.locksverify false

git push --mirror --progress azure

🚧

Check for conflicting URL prefix

Some versions of Azure DevOps contain an additional prefix in the clone URL that will cause authentication errors in Git LFS. If the URL contains DefaultCollection/, delete that part from the string.

3104

Save your build definition and run queue it to run.

You will see that it pulls down changes and commits it to VSTS. You can now make changes in Salesforce through the UI, have Blue Canvas automatically commit those changes to Git and then use this build definition to pull those changes into VSTS.

3104

Next Steps

If you want to run the build script automatically, VSTS allows you schedule builds. Click Triggers and select Scheduled to set it up.

Troubleshooting

Identify your Azure DevOps / VSTS version

https://{hostname}/{organization}/_home/About