Hi Everyone,
I´m currently trying to create my very first pipeline.
My goal is to run some Terraform code covering two scenarios.
The first is whenever a commit is pushed the Plan and Deploy stage needs to be run.
The second is when a tagged commit is pushed.
Then Build, Plan and Deploy stage needs to be run.
So far I came up with the following configuration
stages:
- build
- plan
- deploy
Build AMI:
stage: build
image: registry.gitlab.com/my-packer-image:v1.0
script:
- mkdir ${PACKER_WORKING_DIR} && cd ${PACKER_WORKING_DIR}
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/packer-ami.git .
- packer build -var version="${CI_COMMIT_TAG}"
./ami-template.json
only:
- tags
Plan:
stage: plan
image: registry.gitlab.com/my-terragrunt-image:v1.0
script:
- terragrunt plan-all --terragrunt-non-interactive
Deploy:
stage: deploy
image: registry.gitlab.com/my-terragrunt-image:v1.0
script:
- terragrunt plan-all --terragrunt-non-interactive
However whenever i push a tagged commit two pipelines are created. The first runs the two stages and the second runs all three. This post explains why this is happening.
But the issue is when I tag a commit the pipeline with the two job would always fail, as the Build and Test stages require the new AMI created by the Build stage.
Therefore my question is how can I make sure that tagged commits only create one pipeline?
Any help is appreciated
Thanks