0

How do I access, pipeline variables during the build process. see below. Pipeline Variable

This is what my simple test task looks like:

 steps:
      - bash: echo "Hello World!!! - $(Build.SourceBranch) and DeployType is $(TeamsChannel)"
        displayName: "Started building for $(Build.SourceBranch)"
change198
  • 1,647
  • 3
  • 21
  • 60

2 Answers2

0

You should use this syntax $(VariableName) so in your case $(TeamsChannel).

You are mixing a bit tersm here. You can have few places where you can define variable:

  • pipeline variables tab
  • variable groups
  • yaml

Here you have all three cases:

variables:
- group: PROD
- name: my-bare-variable
  value: 'value of my-bare-variable'

steps:
- script: echo $(isProd) # variable defined in pipeline variables
- script: echo $(my-bare-variable) # variable defined in YAML
- script: echo $(name) # name is variable defined in PROD group
- task: Bash@3
  inputs:
    targetType: 'inline'
    script: 'env | sort'
Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • it's saying command not found, if I add it in one of build task. So, like "variable groups" does it have to be referenced in variable section? if so, then how? – change198 Apr 20 '20 at 07:16
0

Update:

After go through your screenshot, this should be a release pipeline. (Classic UI). But what you are using for test seems to be a yaml pipeline. It's not able to access release variable from a yaml pipeline directly. You should be able to use the variable in tasks of that release pipeline.

Also take a look at this similar question. How to get the variable value in TFS/AzureDevOps from Build to Release Pipeline?


If you are not familiar with variables in Azure DevOps. Suggest you first go through our official doc-- Define variables It describe how to define/set variable, the difference of system variable, system variable, environment, variable scope, secret variable.

Besides, you could also take a look at this blog-- How to pass variables in Azure Pipelines YAML tasks which include three part:

  • Passing variables between tasks in the same job
  • Passing variables between jobs
  • Passing variables between stages
PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • sorry was my typo. I fixed it now in my original question. nonetheless it still says can't find the value. – change198 Apr 20 '20 at 09:47
  • @change198 After go through your screenshot, this should be a release pipeline. (Classic UI). But what you are using for test seems to be a yaml pipeline. It's not able to access release variable from a yaml pipeline directly. You should be able to use the variable in tasks of release. – PatrickLu-MSFT Apr 20 '20 at 10:12
  • thanks @Patrick, this is what I wanted to know. So, in short this is available in release task but not in build . – change198 Apr 20 '20 at 10:26
  • @change198 Yes. You could also take a look at this similar question. https://stackoverflow.com/questions/52568195/how-to-get-the-variable-value-in-tfs-azuredevops-from-build-to-release-pipeline Also update original reply. – PatrickLu-MSFT Apr 20 '20 at 10:39
  • Hi change198,Just checking to see if the information provided was helpful. Do you have any other concern? If my reply helped or gave a right direction. Appreciate for [marking it as an answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) which will also help others in the community. – PatrickLu-MSFT Apr 24 '20 at 10:06