1

I have a repository that I am using as a template for semantic release:

release.yml

workflow:
  rules:
    - if: $CI_COMMIT_TAG
      when: never
    - if: $CI_COMMIT_BRANCH == "test"
      when: always
    - if: $CI_COMMIT_BRANCH == "main"
      when: always

.release:
  image: docker-images/semantic-release-test:v0.2.2
  variables:
    GITLAB_TOKEN: $GITLAB_ACCESS_TOKEN
  script:
    - npx semantic-release --debug

and I am referencing it in another project

.gitlab-ci.yml

stages:
  - release

include:
  - project: templates/semantic-release-test
    file:
      - release.yml

docker_release:
  stage: release
  extends: .release

the problem is that there is still a second pipeline being created after the script creates a new tag. I did try to implement the logic within the .gitlab-ci.yml without the template and it works fine. But when I am using the include key a new pipeline is being triggered regardless.

I have tried many other variation of adding rules to the end of the job or and to the .gitlab-ci.yml as to the release.yml but no luck.

Any ideas on why is that happening?

Kingindanord
  • 1,754
  • 2
  • 19
  • 48

1 Answers1

0

I came across the following in the documentation after reading your question earlier today:

To pass information about the upstream pipeline using predefined CI/CD variables. use interpolation. Save the predefined variable as a new job variable in the trigger job, which is passed to the downstream pipeline.

If I understood it correctly, it should be something like this in your case:

release.yaml

workflow:
  rules:
    - if: $PARENT_TAG
      when: never
    - if: $PARENT_BRANCH == "test"
      when: always
    - if: $PARENT_BRANCH == "main"
      when: always

.release:
  image: docker-images/semantic-release-test:v0.2.2
  variables:
    GITLAB_TOKEN: $GITLAB_ACCESS_TOKEN
  script:
    - npx semantic-release --debug

.gitlab-ci.yml

stages:
  - release

include:
  - project: templates/semantic-release-test
    file:
      - release.yml

docker_release:
  stage: release
  variables:
    PARENT_BRANCH: $CI_COMMIT_BRANCH
    PARENT_TAG: $CI_COMMIT_TAG
  extends: .release

Edit: Later Idea

Though, if you can live with the limitation only disabling it in the parent pipeline, you could also do something like this.

stages:
  - release

include:
  - project: templates/semantic-release-test
    file:
      - release.yml

docker_release:
  stage: release
  extends: .release
  rules:
    - if: $CI_COMMIT_TAG
      when: never
    - if: $CI_COMMIT_BRANCH == "test"
      when: always
    - if: $CI_COMMIT_BRANCH == "main"
      when: always