Search code examples
azureazure-devopsyamlazure-pipelinesazure-pipelines-yaml

Azure DevOps - basic script - echo commands failing in syntax


variables:
    yamlvar : "I'm YAML Variable"
    group : DevGroup

stages:
  - stage: DevStage
    jobs:
     - job: _2019Job
       steps:
        - script: |
           echo $(yamlvar)
           echo $(inputvar)
           echo $(VanisJob)
          displayName: Step1
          name: StepName1

Not able to find where I did wrong in the above YAML code, it is throwing me the below error:

line 1: unexpected EOF while looking for matching `''
line 4: syntax error: unexpected end of file
##[error]Bash exited with code '2'.

Solution

  • You can add the double quote echo "$(yamlvar)" to avoid the avoid failure due to the single quote in $(yamlvar).

    At the same time, according to Use a variable group, if you use both variables and variable groups, use the name/value syntax for the individual non-grouped variables.

    So I changed the yaml code as the following one and it works. (I refer to the variable definition you posted in this post.)

    variables:
    - name: yamlvar
      value: "I'm YAML Variable"
    - group : DevGroup
    
    stages:
      - stage: DevStage
        jobs:
         - job: _2019Job
           steps:
            - script: |
               echo "$(yamlvar)"
               echo $(inputvar)
               echo $(VanisJob)
              displayName: Step1
              name: StepName1
    

    Input:

    enter image description here

    enter image description here

    Output:

    enter image description here