Reputation: 683
I have a pipeline 'A' which has two stages- dev, prod. After dev environment finishes I want prod stage to be triggered only if pipeline 'B' is ran successfully. I want stage 'prod' of pipeline 'A' to be dependent on pipeline 'B'. Is this feasible?
Upvotes: 0
Views: 2199
Reputation: 2196
1.Intasll this Azure DevOps Extension
2.In your Dev stage, add Trigger Build task to ensure you could trigger pipeline B and check the latest build result of pipeline B.
3.Create the Generic Service Connection.
4.Use Invoke REST API in Environment Approvals and checks.
5.After check pass, second stage will depend on the success build of Pipeline B.
trigger:
- none
stages:
- stage: Dev
jobs:
- job: CI
pool:
vmImage: windows-latest
steps:
- task: TriggerBuild@4
inputs:
definitionIsInCurrentTeamProject: true
buildDefinition: 'PipelineB'
queueBuildForUserThatTriggeredBuild: true
ignoreSslCertificateErrors: false
useSameSourceVersion: false
useCustomSourceVersion: false
useSameBranch: true
waitForQueuedBuildsToFinish: false
storeInEnvironmentVariable: false
authenticationMethod: 'Personal Access Token'
password: 'PAT'
enableBuildInQueueCondition: false
dependentOnSuccessfulBuildCondition: false
dependentOnFailedBuildCondition: false
checkbuildsoncurrentbranch: false
failTaskIfConditionsAreNotFulfilled: false
- stage: Prod
dependsOn: Dev
jobs:
- deployment: CD
environment: {EnvironmentName}
pool:
vmImage: windows-latest
strategy:
runOnce:
deploy:
steps:
- task: CmdLine@2
inputs:
script: |
echo Write your commands here
echo Hello world
Upvotes: 1
Reputation: 8082
You can get Pipeline B result in stage dev
(link here), and set it as variable, in the prod
stage, evaluate the variable value to determine the stage to run or not(link here).
Code sample as below:
stages:
- stage: Dev
jobs:
- job: DevJob
steps:
- task: PowerShell@2
name: GetpipelineBresult
inputs:
targetType: 'inline'
script: |
$url = "https://dev.azure.com/{organization}/{pipelineBProject}/_apis/build/builds?definitions={definitionid}&api-version=5.1"
$personalToken = "$(PAT)"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($personalToken)"))
$header = @{authorization = "Basic $token"}
$buildPipeline= Invoke-RestMethod -Uri $url -Headers $header -Method Get
$BuildResult= $buildPipeline.value.result | Select-Object -first 1
Write-Host This is Build Result: $BuildResult
echo "##vso[task.setvariable variable=Buildresult;isOutput=true]$BuildResult"
- stage: Prod
condition: eq(dependencies.Dev.outputs['DevJob.GetpipelineBresult.Buildresult'], 'succeeded')
dependsOn: Dev
jobs:
- job:
steps:
- script: echo job Prod
Pipeline B result: not succeeded(cancel, failed..)
Upvotes: 3