1

I have a yaml build pipeline for a project that has multiple stages, it runs build_and_test then if successful it runs ci_deployment, then dev_deployment etc. I want to add a stage between CI and DEV that runs a seperate repos pipeline, in this case its a ReadyApi repo that will run api tests against the CI environment so if it fails we block the build from proceeding to DEV.

I have got the readyApi pipeline to run the tests against the environment when I run that pipeline but I don't know how to go about tying it into a middle stage of my other pipeline.

So my question is how do I write the stage to run a seperate pipeline, very new to working with yaml so any help with this or resources that could help me to understand would be greatly appreciated.

ReadyApi pipeline:

---
trigger:
  batch: false
  branches:
    include:
    - trunk
pool:
  name: OnPrem TestAgents
  demands: TestRunner -equals ReadyAPI

steps:
- script: |
   powershell 1 | "C:\Program Files (x86)\Java\jre1.8.0_241\bin\java.exe" -jar "C:\ready-api-license-manager\ready-api-license-manager-1.3.2.jar" -s licenseServerUrl
   echo alma
  displayName: 'Command Line Script'


- task: SoapUIProForAzureDevOpsTask@1
  displayName: 'SoapUI Pro for Azure DevOps'
  inputs:
    project: 'ReadyAPI'
    testSuite: API
    projectPassword: 'unencryptkey'


- task: PublishTestResults@2
  displayName: 'Publish Test Results **/*.xml'
  inputs:
    testResultsFiles: '**/*.xml'
    searchFolder: '$(Common.TestResultsDirectory)'
    mergeTestResults: true
    failTaskOnFailedTests: true

Main build pipeline I want to update:

---
trigger:
  batch: false
  branches:
    include:
    - trunk
pool: "poolName"

variables:
  buildMajor: 1
  buildMinor: 3
stages:
- stage: build_and_test
  displayName: Build and Test
  variables:
    azureResourceGroup: 
    azureInfrastructureStateStorageAccount: 
    environmentName: ci
  jobs:
  - job: build_image
  - job: run_unit_test
  - job: run_component_test
  - job: build_and_push_container
   
- stage: ci_deployment
  variables:
    deployment_name: $(serviceName)
    namespace: ci
    environmentName: ci
    buildid: $(buildVersion).$(Build.BuildNumber).$(Build.SourceVersion)
    minReplicas: 1
    maxReplicas: 5
  dependsOn: build_and_test
  jobs:
  - deployment: deploy_to_ci
    environment: ci
    displayName: Deploy to ci
    strategy:
      runOnce:
        deploy:
          steps:
          - template: pipelines/azure-pipelines-deploy.yaml
            parameters:
              environmentName: $(environmentName)
              aadPodIdentityName: $(aadPodIdentityName)
              appConfigName: $(appConfigName)
              keyVaultName: $(keyVaultName)
- stage: dev_deployment
  variables:
    deployment_name: $(serviceName)
    namespace: dev
    environmentName: dev
    buildid: $(buildVersion).$(Build.BuildNumber).$(Build.SourceVersion)
    minReplicas: 3
    maxReplicas: 10
  dependsOn: ci_deployment
  jobs:
  - deployment: deploy_to_dev
    environment: dev
    displayName: Deploy to dev
    strategy:
      runOnce:
        deploy:
          steps:
          - template: pipelines/azure-pipelines-deploy.yaml
            parameters:
              environmentName: $(environmentName)
              aadPodIdentityName: $(aadPodIdentityName)
              appConfigName: $(appConfigName)
              keyVaultName: $(keyVaultName)
Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • 1
    See [How to trigger one pipeline stage from another pipeline in Azure DevOps?](https://stackoverflow.com/questions/68096375/how-to-trigger-one-pipeline-stage-from-another-pipeline-in-azure-devops/68096909#68096909) – qbik Jun 30 '21 at 11:32
  • @qbik Thanks that's exactly what I was looking for, wasn't sure how to hook it into the stages of my pipeline but with the help from the answer below I now have it working – Hosertheposer Jul 01 '21 at 15:45

1 Answers1

1

If you want to block proceeding original pipeline I would recommend you to use this extension Trigger Build Task

You may define it here trigger in a stage between ci_deployment and dev_deployment so it will be waiting for sucessfull run of your tests:

- stage: ci_tests
  dependsOn: ci_deployment
  jobs:
  - job:
    steps:
    - task: TriggerBuild@3
      displayName: 'Trigger a new build of Validate-BuildVariable Update'
      inputs:
        buildDefinition: 'Your build name'
        useSameBranch: false
        branchToUse: master
        waitForQueuedBuildsToFinish: true
        authenticationMethod: 'OAuth Token'
        password: $(System.AccessToken)
- stage: dev_deployment
  .....
  dependsOn: ci_tests
Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • 1
    Thanks @Krzysztof thats exactly what I was looking for, took a bit of time to get working (I had just US12345 in the branchToUse, I missed UserStory/ prefix and the error wasn't helpful (Could not queue the build because there were validation errors or warnings.)) and now my pipeline is building or not based on tests pipeline. Many Thanks. Sorry don't have enough rep to upvote but I have marked as accepted answer – Hosertheposer Jul 01 '21 at 15:50
  • 1
    All fine. I'm happpy that you solved your issue! – Krzysztof Madej Jul 01 '21 at 15:53