This post is to help developers who are new to Azure DevOps releases and deploying a VS Code extension. Azure pipelines come with lots of great options but it can be difficult to know what to do to achieve your goal. The goal in this case is to deploy my VS Code extension, Git Mob to the marketplace.
I’ll provide bite size instructions to help you build a release for your VS Code extension using Azure DevOps platform. This will take about 5-10mins.
Build a release pipeline to VS Code marketplace
This article assumes you have built a .vsix
artifact from am Azure DevOps pipeline. If not, I have created a post on how to make a continuous delivery pipeline for your VS Code extension. I wanted to keep this post about deploying via Azure pipeline specifically, to keep the steps focused.
Deploy to VS Code marketplace
We will create a “release” to deploy the built artifact to the marketplace. The YAML example at the end of the steps illustrates the commands needed to release the artifact via Azure DevOps pipeline.
Azure release pipeline UI showing areas covered in these steps
- In the left hand navigation bar under Pipelines select Releases
- Open the New dropdown and select New release pipeline
- You will be asked to select a template, unfortunately there is not one for deploying extensions to the marketplace. Select Empty job.
- You will only need one stage, name it what you like.
- Select Add an artifact box
- Source type is Build and Source will be the first item in the dropdown. It will be the name of your Git repository.
- Default version is set to latest but you can of course change this.
- Click the Add button when you’re ready.
- In stages box click the small link 1 Jobs, 0 task.
- On Agent Job click the plus button and search for “bash” task. Then click add.
- Type select Inline
- Copy the commands from the YAML example below starting from
sudo ...
to.vsix
- Under the Advanced tab, working directory click the ellipsis (…) button on the right and select the folder which contains the
.vsix
artifact file. - Using your marketplace Personal Access Token (PAT) we will set an environment variable called
MARKET_KEY
. Get & save PAT securely - In the environment variables tab add name
MARKET_KEY
and value$(nameOfSecureVariable)
- Ensure you save these changes and you should be ready to “create a release”.
Execute your release pipeline
- To run your new release pipeline click the create release button in the top right
- A side menu will appear, all the fields are optional so you can click create
YAML example showing how to release you VS Code extension to the marketplace.
Important points:
vsce publish
is the app & command to deploy to VS Code marketplace-p $MARKET_KEY
send your PAT to authorise publishing--packagePath git-mob-$PACKAGE_VERSION.vsix
the extension package to publish
steps:
- bash: |
sudo npm install -g vsce
PACKAGE_VERSION=$(cat version.txt)
vsce publish -p $MARKET_KEY --packagePath git-mob-$PACKAGE_VERSION.vsix
workingDirectory: "$(System.DefaultWorkingDirectory)/_rkotze.git-mob-vs-code"
displayName: Deploy
env:
MARKET_KEY: $(vscekey)
Here is the Git Mob release pipeline for reference.
Get & save PAT securely
- To publish to the marketplace you will need a Personal Access Token which is explained here on publishing extensions.
- Once you have a key, it will need to be stored privately so it can be used in the release pipeline without it being revealed in the build log. Ensure your work is saved and now let’s store that token.
- Click the variables tab on the top left.
- Insure Pipeline variables is selected on the left and click the + Add button.
- Add a name e.g. “vscekey” and the value is your PAT. Ensure the padlock is locked to make it a secret.
- Your secret variable is now ready to be accessed by the release pipeline.
- Finish the remaining steps above to complete the release pipeline.
I hope this has helped you to deploy your extension. Please comment below if this was useful or you came across an issue which could help others.