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

Using YAML Anchors for shared step - that includes a pipe

Brett James February 3, 2023

I want to use the "definitions" section to specify a shared step as demonstrated here -  https://support.atlassian.com/bitbucket-cloud/docs/yaml-anchors/

However the step I want to make common uses a pipe for deployment (microsoft/azure-aks-deploy:1.0.2), and it doesn't seem to format correctly or be allowed to be used under "definitions"

Is there a way to do this?

Here are the two steps at the moment, with plenty of duplication:

 branches:

    main:

      - step:

          name: Deploy to dev

          deployment: dev

          script:

            - make generate-k8s-config NAMESPACE=$NAMESPACE

            - pipe: microsoft/azure-aks-deploy:1.0.2

              variables:

                AZURE_APP_ID: $ARM_CLIENT_ID

                AZURE_PASSWORD: $ARM_CLIENT_SECRET

                AZURE_TENANT_ID: $ARM_TENANT_ID

                AZURE_AKS_NAME: $CLUSTER_NAME

                AZURE_RESOURCE_GROUP: $CLUSTER_RESOURCE_GROUP

                KUBECTL_COMMAND: "apply"

                KUBECTL_ARGUMENTS: "-f $DEPLOYMENT_CONFIG --namespace $NAMESPACE"

                DEBUG: "true"

      - step:

          name: Deploy to QA

          deployment: qa

          script:

            - make generate-k8s-config NAMESPACE=$NAMESPACE

            - pipe: microsoft/azure-aks-deploy:1.0.2

              variables:

                AZURE_APP_ID: $ARM_CLIENT_ID

                AZURE_PASSWORD: $ARM_CLIENT_SECRET

                AZURE_TENANT_ID: $ARM_TENANT_ID

                AZURE_AKS_NAME: $CLUSTER_NAME

                AZURE_RESOURCE_GROUP: $CLUSTER_RESOURCE_GROUP

                KUBECTL_COMMAND: "apply"

                KUBECTL_ARGUMENTS: "-f $DEPLOYMENT_CONFIG --namespace $NAMESPACE"

                DEBUG: "true"

 

1 answer

1 accepted

1 vote
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 7, 2023

Hi @Brett James and welcome to the community!

This should be possible. Can you try using a config like below?

definitions:
steps:
- step: &deploy
script:
- make generate-k8s-config NAMESPACE=$NAMESPACE
- pipe: microsoft/azure-aks-deploy:1.0.2
variables:
AZURE_APP_ID: $ARM_CLIENT_ID
AZURE_PASSWORD: $ARM_CLIENT_SECRET
AZURE_TENANT_ID: $ARM_TENANT_ID
AZURE_AKS_NAME: $CLUSTER_NAME
AZURE_RESOURCE_GROUP: $CLUSTER_RESOURCE_GROUP
KUBECTL_COMMAND: "apply"
KUBECTL_ARGUMENTS: "-f $DEPLOYMENT_CONFIG --namespace $NAMESPACE"
DEBUG: "true"

pipelines:
branches:
main:
- step:
<<: *deploy
name: Deploy to dev
deployment: dev
- step:
<<: *deploy
name: Deploy to QA
deployment: qa

Regarding indentation, you need to use at least 1 space, except for everything listed under - step: which should be at least 3 spaces. In the example above I used 2 and 4 spaces respectively.

If you get any errors with this config, please feel free to let me know what errors you see and we can look into it.

Kind regards,
Theodora

Deleted user March 10, 2023

I have similar question but I do not want to use deployment since I need to change the variable. Is it possible to do so? In my case, only 1 variable changes SERVICE_TO_DEPLOY. I am thinking to use deployment but I am not sure how many are allowed and whether it is right thing to do just because of 1 variable

 

      - parallel:

          - step:

              name: Deploy Identity Service Main to Feature

              script:

                - echo "deploy identity service"

                - export SERVICE_TO_DEPLOY=identityservice

                - echo "Deploy service ${SERVICE_TO_DEPLOY}"

                - pipe: atlassian/trigger-pipeline:5.1.0

                  variables:

                    BITBUCKET_USERNAME: $BB_INTEGRATION_USER

                    BITBUCKET_APP_PASSWORD: $BB_INTEGRATION_TOKEN

                    REPOSITORY: ${SERVICE_TO_DEPLOY}

                    REF_TYPE: "branch"

                    REF_NAME: "pipelines"

                    CUSTOM_PIPELINE_NAME: "main-to-feature-deploy"

                    PIPELINE_VARIABLES: >

                      [{

                        "key": "BRANCH_TO_DEPLOY",

                        "value": "${BITBUCKET_BRANCH}"

                      },

                      {

                        "key": "SOURCE_REPO_NAME",

                        "value": "$BITBUCKET_REPO_SLUG"

                      }]

                    WAIT: "true"

          - step:

              name: Deploy Admin Service Main to Feature

              script:

                - echo "deploy admin service"

                - export SERVICE_TO_DEPLOY=adminservice

                - echo "Deploy service ${SERVICE_TO_DEPLOY}"

                - pipe: atlassian/trigger-pipeline:5.1.0

                  variables:

                    BITBUCKET_USERNAME: $BB_INTEGRATION_USER

                    BITBUCKET_APP_PASSWORD: $BB_INTEGRATION_TOKEN

                    REPOSITORY: ${SERVICE_TO_DEPLOY}

                    REF_TYPE: "branch"

                    REF_NAME: "pipelines"

                    CUSTOM_PIPELINE_NAME: "main-to-feature-deploy"

                    PIPELINE_VARIABLES: >

                      [{

                        "key": "BRANCH_TO_DEPLOY",

                        "value": "${BITBUCKET_BRANCH}"

                      },

                      {

                        "key": "SOURCE_REPO_NAME",

                        "value": "$BITBUCKET_REPO_SLUG"

                      }]

                    WAIT: "true"
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 13, 2023

Hi @[deleted],

You could do this with deployment environments or without. If you use deployment environments, you can create a deployment variable with the same name under each environment, and then give a different value to that variable depending on the environment. You don't need to assign a value then in the step's script.

For a repo belonging to a workspace on the Free plan, there is a limit of 10 deployment environments. If the repo belongs to a workspace on a paid billing plan, the limit is 100.

If you don't want to use deployments, you could also use a yaml anchor only for the pipe. I see that you already figured this out here:

If you have any questions, please create a new post and we can look into them.

Kind regards,
Theodora

Like Deleted user likes this
Deleted user March 13, 2023

Thanks @Theodora Boudale , I was able to deployments and anchors.

Like Theodora Boudale likes this

Suggest an answer

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

Atlassian Community Events