DEV Community

Jeg
Jeg

Posted on

1

Setting up variables in Azure-Devops pipelines

To add a variable in the pipeline yaml files:

trigger:
- none

name: $(TeamProject)-$(SourceBranchName)-$(Build.BuildId)-$(Hours)$(Minutes)$(Seconds)-$(Date:yyyyMMdd)$(Rev:.r)

variables: 
  MyDockerTag: '$(Build.BuildId)'

pool:
  name: DemoPool
  demands:
  - Agent.Name -equals $(agentname)

stages:
- stage: Build
  displayName: Build stage
  jobs:
  - job: Build
    timeoutInMinutes: 0 
    displayName: Build
    pool:
      name: DemoPool
      demands:
      - Agent.Name -equals $(agentname)
    steps:

    - task: Docker@2
      inputs:
        containerRegistry: 'registry-name'
        repository: '$(namespace)'
        command: 'build'
        Dockerfile: '**/Dockerfile'
        tags: 'latest'

     - task: Docker@2
      inputs:
        containerRegistry: 'registry-name'
        repository: '$(namespace)-test'
        command: 'push'
        tags: '$(MyDockerTag)'
Enter fullscreen mode Exit fullscreen mode

The trigger none - says the build is not auto-triggered whenever there is code push. Variables are defined in the variables section.

$(Build.BuildId) is the system variable and that would have the build number as the value.

For agentname and namespace, the variable can be defined globally as shown below:

Image description

👋 While you are here

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay