Steve
Steve

Reputation: 1316

Azure DevOps YAML build pipeline - Set script task name

I have a YAML build pipeline with a simple script task that sets the build configuration based on the branch being built:

- script: |
    echo Current branch is %BUILD_SOURCEBRANCHNAME%
    if %BUILD_SOURCEBRANCHNAME% == "master" (
        SET BUILD_CONFIG=Release
    ) else (
        SET BUILD_CONFIG=Debug
    )
    echo ##vso[task.setvariable variable=BuildConfiguration]%BUILD_CONFIG%
    echo BuildConfiguration set to '%BUILD_CONFIG%'

This works fine but the task appears in the list as 'CmdLine' and I'd like something a little more descriptive. The example in the MS documentation indicates that I should be able to add a displayName entry to the end:

- script: |
    echo Current branch is %BUILD_SOURCEBRANCHNAME%
    if %BUILD_SOURCEBRANCHNAME% == "master" (
        SET BUILD_CONFIG=Release
    ) else (
        SET BUILD_CONFIG=Debug
    )
    echo ##vso[task.setvariable variable=BuildConfiguration]%BUILD_CONFIG%
    echo BuildConfiguration set to '%BUILD_CONFIG%'
    displayName: 'Determine Build Configuration'

However, this fails with 'displayName:' is not recognized as an internal or external command, operable program or batch file.

Such a simple thing but I've tried everything I can think of and just can't get it to work!

Upvotes: 0

Views: 4265

Answers (1)

4c74356b41
4c74356b41

Reputation: 72191

fix indentation:

- script: |
    echo Current branch is %BUILD_SOURCEBRANCHNAME%
    if %BUILD_SOURCEBRANCHNAME% == "master" (
        SET BUILD_CONFIG=Release
    ) else (
        SET BUILD_CONFIG=Debug
    )
    echo ##vso[task.setvariable variable=BuildConfiguration]%BUILD_CONFIG%
    echo BuildConfiguration set to '%BUILD_CONFIG%'
  displayName: 'Determine Build Configuration'

Upvotes: 3

Related Questions