Mark
Mark

Reputation: 560

Create Stage that can be Called from Another Stage or Manually?

Hi I have a pipeline dependency challenge and have thought up a number of possible solutions. I can try them all out in a lab but the problem I am wondering if they work well "in the field" and so would like to know if anyone has tried them?

I have 3 stages, each in their own YML file. Each one is called from a main YML which is called from a main pipeline.

- template: 'build.yml'
- template: 'deploy.yml'
- template: 'test.yml'

The 'deploy.yml' generates a large number of output environment variables and 4 of these are consumed by the 'test.yml' using the "stageDependencies" syntax:

stages:
- stage: 'Test_Stage'
  dependsOn: Deploy_Stage
  jobs:
    job: 'Test_Job'
    variables:
      MyWebSite: [ stageDependencies.Deploy_Stage.Variables_Job.outputs['Variables_Job.Variables.MyWebSite'] ]

This works nicely.

But, I'd like to be able to create a pipeline that just does the test stage (to test a pre-existing web site). That doesn't work of course because of the dependency dependsOn: Deploy_Stage.

I can think of a few possible solutions:

  1. Instead of having a dependency and using the [ stageDependencies... ] syntax, send the MyWebSite as a pipeline parameter between stages. (Note that there are actually parameters not 1, I just simplified to demonstrate the challenge.) If I do that, the tester gets prompted to fill out (or choose from a list) the various parameters. But, it does create linkage between Deploy_Stage and Test_Stage - I don't know if that's a bad thing?

  2. Pass a Boolean parameter from Deploy_Stage to Test_Stage such as "CalledFromDeployStage" and then in Test_Stage, do this:

stages:
- stage: 'Test_Stage'
  ${{ if eq(parameters.CalledFromDeployStage, true) }}:
    dependsOn: Deploy_Stage
  jobs:
    job: 'Test_Job'
    variables:
      MyWebSite: [ stageDependencies.Deploy_Stage.Variables_Job.outputs['Variables_Job.Variables.MyWebSite'] ]

This feels a bit clunky.

  1. Create a new YML called "Test_Stage_Manual" and get it to prompt for the various parameters and leave the rest as-is. (If I do this, I would probably put the jobs into their own YML file and call that YML from both Test stages.)

  2. Something else?

Upvotes: 0

Views: 770

Answers (1)

Bright Ran-MSFT
Bright Ran-MSFT

Reputation: 13444

You can try like as below:

  1. Create an individual YAML pipeline to only run the test.

  2. In the "Deploy_Stage" of the main pipeline, add a step or job at the end of this stage to execute the API "Runs - Run Pipeline" to trigger the pipeline for test after all the previous steps and jobs in this stage are completed successfully.

  3. When calling the "Runs - Run Pipeline" API, you can pass the variables and parameters generated in the "Deploy_Stage" to the pipeline for test via the Request Body (JSON type) of the API.

  4. Due to the test is in an individual pipeline, you can manually trigger this pipeline if you like. When manually trigger, you can manually set the value of the required variables and parameters in the pipeline.

With this way, you can trigger the pipeline for test both via the "Deploy_Stage" and manually.

Upvotes: 1

Related Questions