Missed Team ’24? Catch up on announcements here.

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

Re-use step with different variable

kbaley January 20, 2023

I have a step that executes a custom .NET tool to migrate a legacy database. It's designed to take a parameter representing the database to migrate so that you can call it like so:

dotnet run -- SC
dotnet run -- AL
dotnet run -- GA

Each run will migrate the specified database. I can set up a step to execute these three lines one after another in a single script within a single step but I'd like to be able to run them in parallel. So I have a boilerplate anchored step with all the pre-amble script that eventually culminates in

dotnet run -- ${STATE}

But now I'm having trouble figuring out how to arrange the parallel steps to pass in the contents of the ${STATE} variable to each instance of the step.

I've searched the forum and elsewhere and discovered it's not easy to do this. I found an open issue (that I've since lost) to allow sharing variables across steps. I also found one trick to save the variable you want as an artifact to be picked up by the later step but I'm not sure that will work because as far as I know, I'll just end up overwriting the same artifact used by the shared step for each iteration. So I'm wondering what's a good workaround that will let me execute many instances of this shared step, each with a different value for this one ${STATE} variable.

1 answer

1 accepted

0 votes
Answer accepted
Erez Maadani
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 22, 2023

Hey @kbaley 

You can try and wrap the step's script in a file and then pass the state as an argument to the script. Something like this:

- step:
   script:
      - ./my_script "SC"

- step:
   script:
      - ./my_script "AL"

Hope that helps

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events