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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.