SteeveDroz
SteeveDroz

Reputation: 6136

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

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:

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

How to fix my CI?

Upvotes: -1

Views: 498

Answers (1)

SteeveDroz
SteeveDroz

Reputation: 6136

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"

Upvotes: 0

Related Questions