In this lab we will find our way through Azure DevOps. The main steps will be:
demoapp
.Make sure you created an ssh key with ssh-keygen
for your local machine and uploaded the public key (id_rsa.pub
)
to your Azure DevOps profile, so that you can use git and ssh without being nagged with passwords.
to your Azure DevOps profile, so that you can use git and ssh without being nagged with passwords.
$ cd <sourcedir> $ git init $ git add . $ git commit -m "Adding the demo app to git"
SSH
tab and follow the instructions:
git remote add origin git@ssh.dev.azure.com:v3/<yourorg>/<yourproject>/demoapp git push -u origin --all
Your code should now be in an Azure git repository.
The idea of a pipeline is to have some automation kicked off on each and every git push
or creation and merge of a
git pull request.
While many projects use TravisCI or a separate Jenkins server to do
that part of automation, Azure uses its own pipeline.
This requires that in your repository there is a specific file named azure-pipelines.yaml
, which we will now create,
step-by-step.
Limited local testing can be achieved by runnig a local pipeline agent.
First, we need to create a connection to the Azure registry with a service connection. To do so, go to Azure DevOps and click on Project Settings at the botton left of your browser window, then click on Service connections under Pipelines.
Click on New Service connection and select Docker Registry. In the pop-up window, select Azure Container Registry and provide the relevant data.
azure-pipelines.yml
with the following
content:
trigger:
pool: vmImage: ‘ubuntu-latest’
variables: imageName: demoapp:$(build.buildId)
steps:
</pre>
$ git add azure-pipelines.yml $ git commit -m "added pipeline" $ git push
azure-pipelines.yml
and select Existing Azure Pipelines YAML file./azure-pipelines.yml
and hit Continueazure-pipelines.yml
is shown and to manually run it, hit the Run button on the top right of the page.##Extend the pipeline
azure-pipelines.yml
:
: variables: dockerRegistry: <your registry name> : - task: Docker@2 displayName: Login to ACR inputs: command: login containerRegistry: <your registry connnection> - task: Docker@2 displayName: Build and Push inputs: command: buildAndPush containerRegistry: <your registry connnection> repository: $(dockerRegistry).azurecr.io
Now, here’s the challenge of the day: YAML files rely on indention, so be perfectly sure everything is perfectly indented otherwise your pipeline either won’t work or will do funny things you didn’t exactly ask for.
azure-pipelines.yml
:
$ git add azure-pipelines.yml $ git commit -m "added docker build" $ git push
Once you pushed your changes, you can see the pipeline being run with a new job. Inspect the results to see what happened in either good or bad case :-)