0

I am new to azure pipelines. I am using Azure devops pipeline to trigger another devops pipeline. Pipelines are written in YAML schema.

Pipeline A

- task: TriggerBuild@3
    displayName: Trigger Setup Pipeline
    inputs:
      definitionIsInCurrentTeamProject: true
      buildDefinition: '111'
      queueBuildForUserThatTriggeredBuild: true
      ignoreSslCertificateErrors: false
      useSameSourceVersion: false
      useCustomSourceVersion: true
      customSourceVersion: '$(Revision)'
      useSameBranch: true
      waitForQueuedBuildsToFinish: true
      waitForQueuedBuildsToFinishRefreshTime: '60'
      failTaskIfBuildsNotSuccessful: true
      cancelBuildsIfAnyFails: false
      treatPartiallySucceededBuildAsSuccessful: false
      downloadBuildArtifacts: false
      storeInEnvironmentVariable: false
      authenticationMethod: 'OAuth Token'
      password: '$(PersonalToken)'
      enableBuildInQueueCondition: false
      dependentOnSuccessfulBuildCondition: false
      dependentOnFailedBuildCondition: false
      checkbuildsoncurrentbranch: false
      failTaskIfConditionsAreNotFulfilled: false

Pipeline B

- task: DownloadBuildArtifacts@0
  condition: and(succeeded(), eq(variables['WCBuildType'], 'Internal'))
  inputs:
    buildType: 'specific'
    project: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
    pipeline: '999'
    buildVersionToDownload: 'latestFromBranch'      # I want to use '$(Revision)' vaue here
    branchName: '$(Build.SourceBranch)'
    downloadType: 'single'
    artifactName: 'Compiled'
    downloadPath: 'Artifact'
  displayName: 'Download build artifacts'

I want to use $(Revision) value of pipeline A in pipeline B to download artifact of particular build version. I also want trigger of Pipeline B should behave differently in these two conditions:

  1. Whenever user make any commit in his branch, then it should use buildVersionToDownload: latestFromBranch
  2. Whenver user trigger pipeline A, then Pipeline B got triggered and use buildVersionToDownload: $(Revision) to download build artifacts.
Manish Jain
  • 1,197
  • 1
  • 11
  • 32

1 Answers1

0

In the TriggerBuild@3 task add this line:

buildParameters: 'Revision: $(Revision)'

It will send the variable to the triggered build.

Now, in Pipeline B you can create if to check if the user made the commit or it's triggered pipeline:

${{ if eq(variables['Build.Reason'], 'IndividualCI') }}:
  buildVersionToDownload: 'latestFromBranch'
${{ if ne(variables['Build.Reason'], 'IndividualCI') }}:
  buildVersionToDownload: '$(Revision)'
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114