0

I want to use a counter to have unique build numbers in case my version string has not changed.

This is my config:

  - task: Bash@3
    name: GetSemVer
    displayName: Get semantic version
    inputs:
      targetType: 'inline'
      script: |
        SEMVER=$(./gradlew printVersion | grep 'Version: ' | awk -F' ' '{print $2}')
        echo "##vso[task.setvariable variable=semver;isOutput=true]$SEMVER"
        BUILDINCREMENT=$[counter('semver', 0)]
        BUILDVERSION=$SEMVER$optionalBuildTag-$BUILDINCREMENT
        echo "##vso[build.updatebuildnumber]$BUILDVERSION"

I want to get a version like this:

1.0.0-beta.2+029.sha.16177d4-1

But I get this error:

/home/vsts/work/_temp/7388d9ae-e885-4bcb-b6a7-4226978a77d7.sh: line 3: counter('semver', 0): syntax error in expression (error token is "('semver', 0)")
Async Command Start: Update Build Number
Update build number to 1.0.0-beta.2+029.sha.16177d4- for build 6742
Async Command End: Update Build Number

The counter suffix is missing from the build-number.

3
  • I don't think it's possible to mix runtime expressions like $[counter] and variables defined during a pipeline's run. Commented Aug 28, 2023 at 16:47
  • I am using to jobs now, where I echo the SEMVER in the first and define the other variables in the variables block of the second job. Commented Aug 30, 2023 at 8:05
  • @mrt181 can you please explain further how you solved that? I am not able to get this work Commented Dec 9, 2024 at 14:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.