Home > OS >  Why is my variable value not getting updated in azure pipeline?
Why is my variable value not getting updated in azure pipeline?

Time:06-21

I want to update a variable based on the number of commits in git repo. I am correctly able to fetch the count but not able to update the variable for further use. Any idea what is going wrong.

variables:
  # Versioning
  # Version Format - 'VersionMajor.VersionMinor.VersionRelease.Revision'
  # Currently the Major, Minor and Minor are all constants
  - name: VersionMajorMinorRelease
    value: '1.0.1'
    
  # Revision will be calculated during pipeline run based on total commit counts for branch
  - name: VersionRevision
    value: ''

Further in job I am using variables as

- task: PowerShell@2
    displayName: Set the build version
    condition: eq('${{ parameters.Action }}', 'BuildAndDeploy')
    inputs:
      targetType: inline
      script: |
        $commitCounts= $(git rev-list --count HEAD)
        $revision= $commitCounts.ToString()
        Write-Host "Revision = '$revision'"
        Write-Host "##vso[task.setvariable variable=VersionRevision]$revision"
        Write-Host "Version of App being built = '$(VersionMajorMinorRelease).$(VersionRevision)'"
      

Output printed -

Revision = '1660'
Version of App being built = '1.0.1.'

CodePudding user response:

Why is my variable value not getting updated in azure pipeline?

You could use the VersionRevision in next task.

According to the document Set variables in scripts:

When you use PowerShell and Bash scripts in your pipelines, it's often useful to be able to set variables that you can then use in future tasks.

That is reason why you able to fetch the count but not able to update the variable for further use, please try to echo it in next powershell task.

  • Related