How can I dynamically pass multiple Role ARNs defined in my Bitbucket repository environment variable to a step variable in my pipeline?
I have three Role ARNs defined in my Bitbucket repository environment variable, named OIDC_ROLE_ARN_dev, OIDC_ROLE_ARN_stage, and OIDC_ROLE_ARN_master, corresponding to the branch names dev, stage, and master, respectively. I want to dynamically select the appropriate Role ARN based on the current branch and use it as a step variable.
I've attempted to achieve this using Indirect expansion like OIDC_ROLE_ARN="OIDC_ROLE_ARN_${BITBUCKET_BRANCH}" and then using ${!OIDC_ROLE_ARN}. While this works fine locally, it throws a syntax error "bad substitution" in the pipeline environment.
Here's my pipeline step:
- step: &build-and-push-fitserver-image
name: Build and Push fitServer Image to ECR
oidc: true
script:
- OIDC_ROLE_ARN="OIDC_ROLE_ARN_${BITBUCKET_BRANCH}"
- docker build -t fitserver:${BITBUCKET_BRANCH} -t fitserver:latest .
- pipe: atlassian/aws-ecr-push-image:2.4.0
variables:
AWS_OIDC_ROLE_ARN: ${!OIDC_ROLE_ARN}
IMAGE_NAME: fitserver
TAGS: "${BITBUCKET_BRANCH} latest"
Could someone please suggest a way to resolve this issue without using if-else conditions?