Avoid configuration duplication when secrets change

Hello all,

I’ve dive into the documentation but can’t find anything that help me.
How can I avoid duplicate some job configuration where the only changes concern the secrets to use (production, staging, qa).
Do you have any ideas.

Thanks.

Hi there,

Usually, the easiest way to avoid duplicating job configuration and commands is to use the prologue property.

Does this feature adjust to your needs? If not, maybe a snippet of the pipeline file might help to better understand your use-case.

Best,

@Christian_Semaphore yes a snippet of code will make it clear, prologue doesn’t concern our case

  - name: "WEB - Build staging AMI"
    dependencies: ["WEB - Lint & Test"]
    run:
      when: "branch = 'develop'
    task:
      secrets:
        - name: aws
        - name: staging
      prologue:
        commands:
          - sem-version node 12.19.0
          - yarn install
          - wget -q https://releases.hashicorp.com/packer/1.3.5/packer_1.3.5_linux_amd64.zip
          - unzip packer_1.3.5_linux_amd64.zip -d bin
          - pip install -qq --user --cache-dir .pip_cache ansible==2.9.7
      jobs:
        - name: Packer Build WEB AMI Staging
          commands:
            - yarn generate-packer-variables // take current env variables to create the packer_variables file
            - ./bin/packer build -var-file=ci/ansible/roles/env/vars/packer_variables.json ci/packer/template.json

  - name: "WEB - Build qa AMI"
    dependencies: ["WEB - Lint & Test"]
    run:
      when: "branch = 'qa'
    task:
      secrets:
        - name: aws
        - name: qa
      prologue:
        commands:
          - sem-version node 12.19.0
          - yarn install
          - wget -q https://releases.hashicorp.com/packer/1.3.5/packer_1.3.5_linux_amd64.zip
          - unzip packer_1.3.5_linux_amd64.zip -d bin
          - pip install -qq --user --cache-dir .pip_cache ansible==2.9.7
      jobs:
        - name: Packer Build WEB AMI Qa
          commands:
            - yarn generate-packer-variables // take current env variables to create the packer_variables file
            - ./bin/packer build -var-file=ci/ansible/roles/env/vars/packer_variables.json ci/packer/template.json

Hi @ggaulard,

If I’m not mistaken, it seems that the prologue and commands from jobs WEB - Build staging AMI and WEB - Build qa AMI are pretty much the same. The only differences are run when and secrets.
Being that the case, I recommend then the global_job_config feature. By using this, you can merge the prologues from both jobs, saving up some lines. You could also include the secrets leaving only run when and commands for each job.

I hope this helps.