Search code examples
azure-devopsazure-pipelinesazure-pipelines-yamlready-api

Azure Devops pipeline call separate e2e repo between ci and dev deployment stages


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)

Solution

  • 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