Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can I re-use steps with slight variations in the scripts between pipelines?

Michiel February 18, 2020

I have defined a step to build and test .NET code that I want to re-use in multiple pipelines:

definitions:
steps:
step: &prepare
name:
script:
- dotnet build --configuration Debug
- dotnet test --configuration Debug --no-build

pipelines:
pull-requests:
feature/*:
- step: *prepare
branches:
master:
- step: *prepare

When the pipeline for the `master` branch is run, I need to pass `--configuration Release` instead of `--configuration Debug`, so that the artifacts are optimized.

How can I re-use this `prepare` step with a slight variation in the scripts between pipelines? Can I declare variables per pipeline and refer to them in the scripts?

I tried to use a `variables` section as part of the pipeline, but that is not allowed for pipelines targeting `pull-requests` or `branches`. It is only allowed for custom pipelines.

P.S.

I know I can use YAML's ability to merge, but that only allows me to customize pre-defined step properties per pipeline, such as `trigger` or `environment`. Although powerful, this does not help in this scenario, where the customization is required at the level of an individual script.

One work-around is to use Bash scripting to inspect the current branch, and derive the correct values for the command-line options from that. But I'd rather use a declarative solution, since that is easier to write and easier understand.

Another work-around is to declare the step to be a deployment step, and then start using deployment variables. But I think most would agree that build and test is not deployment, so declaring the step as a deployment step is indeed a work-around.

 

1 answer

0 votes
Michiel February 18, 2020

<deleted>

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events