How can I run a pipeline automatically, taking a value from the context, or manually with a default value?

266 views Asked by At

I have a CI that runs when a tag is created, but I would like to be able to run it manually as well. Unfortunately, the CI uses the tag name to set the name of the artifact.

I tried this:

stages:
  - build

workflow:
  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_JOB_MANUAL
      variables:
        - CI_COMMIT_TAG: "manual"

build_app:
  script:
    - echo "Build completed"
  artifacts:
    expire_in: 30 days
    paths:
      - .
    name: "app-$CI_COMMIT_TAG"

What I would like is:

  • With git tag v2.4.1 && git push --tags, it should create the artifact app-v2.4.1.zip.
  • With "Pipeline --> Run pipeline", it should create the artifcat app-manual.zip.

Unfortunately, I can't run it manually (Pipelines --> Run Pipeline) because "Pipeline filtered out by workflow rules."

How to fix my CI?

1

There are 1 answers

0
SteeveDroz On

Instead of $CI_JOB_MANUAL, you have to use $CI_PIPELINE_SOURCE and compare it to "web". Here is the complete file:

stages:
  - build

workflow:
  rules:
    - if: $CI_COMMIT_TAG
    - if: '$CI_PIPELINE_SOURCE == "web"'
      variables:
        - CI_COMMIT_TAG: "manual"

build_app:
  script:
    - echo "Build completed"
  artifacts:
    expire_in: 30 days
    paths:
      - .
    name: "app-$CI_COMMIT_TAG"