Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Pipelines - Use list to loop in multiple scripts/steps

shall
Contributor
July 21, 2022

In my bitbucket pipeline, in multiple steps and scripts, I want to loop through a common list of strings.

Azure Pipelines shows an example of how to do this in the "Loop through parameters section": https://docs.microsoft.com/en-us/azure/devops/pipelines/process/runtime-parameters?view=azure-devops&tabs=script

However this syntax is not valid according to the bitbucket-pipelines.yml validator tool: https://bitbucket-pipelines.atlassian.io/validator

How can I do this in Bitbucket Pipelines?

Bonus points if I can do this within a script, as opposed to at the step level.

An example of what I would like to do:

parameters:
- name: myList
type: object
default:
- listString1
- listString2

pipelines:
default:
- step:
- ${{ each exampleString in parameters.myList }}:
- script: echo ${{ exampleString }}

1 answer

1 vote
shall
Contributor
July 21, 2022

I found a similar concept here: https://community.atlassian.com/t5/Bitbucket-questions/Array-value-on-Environment-Variables-for-BitBucket-Pipelines/qaq-p/875894

It uses repository or workspace pipeline variables as an array, which you can then loop through in your bitbucket-pipeline.yml. So this technically works as a solution.

However, I'd have preferred a way to do this inside the yml file as opposed to in Bitbucket settings, since now those variables are not tracked in git, although they can be visible in pipeline logs.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events