I have defined a step to build and test .NET code that I want to re-use in multiple pipelines:
- dotnet build --configuration Debug
- dotnet test --configuration Debug --no-build
- step: *prepare
- 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.
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.
Hi everyone, We are looking to learn more about development teams’ workflows and pain points, especially around DevOps, integrations, administration, scale, security, and the related challeng...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events