Is it possible to set an VSTS Build variable in a Build Step so that the value can be used in a subsequent Build Step?

前端 未结 4 948
南笙
南笙 2020-12-30 21:40

I\'m currently using Build in Visual Studio Team Services (was Visual Studio Online), and would like to be able to set a Build Variable in a Build Step so that the new value

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-30 22:26

    I found this link helpful: https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=powershell

    This has the complete options of what you can do: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch

    You can reuse set variable from task to task, and also job to job. I couldn't find anything on stage to stage.

    In summary:

    jobs:
    
    # Set an output variable from job A
    - job: A
      pool:
        vmImage: 'vs2017-win2016'
      steps:
      - powershell: echo "##vso[task.setvariable variable=myOutputVar;isOutput=true]this is the value"
        name: setvarStep
      - script: echo $(setvarStep.myOutputVar)
        name: echovar
    
    # Map the variable into job B
    - job: B
      dependsOn: A
      pool:
        vmImage: 'ubuntu-16.04'
      variables:
        myVarFromJobA: $[ dependencies.A.outputs['setvarStep.myOutputVar'] ]  # map in the variable
                                                                              # remember, expressions require single quotes
      steps:
      - script: echo $(myVarFromJobA)
        name: echovar
    

提交回复
热议问题