Search code examples
gitlabgitlab-cicicd

gitlab: How to have a another gitlab-ci.yml and use it whenever i want, instead of automatic triggering


I have a gitlab-ci.yml file, which gets triggered when I commit changes.

I want to have another file gitlab-ci-notrigger.yml which will not be triggered. But I can use this to run pipeline whenever i want manually

enter image description here


Solution

  • You can create a job than must be run manually

    You can require that a job doesn’t run unless a user starts it.
    This is called a manual job.

    You might want to use a manual job for something like deploying to production.

    To specify a job as manual, add when: manual to the job in the .gitlab-ci.yml file.

    By default, manual jobs display as skipped when the pipeline starts.

    The OP adds:

    # WANT deploy-to-stage TO BE RUN ONLY WHEN automatic
    deploy-to-stage:
      stage: staging
      script:
        -..........
    

    Check if using except can help:

    # WANT deploy-to-stage TO BE RUN ONLY WHEN automatic
    deploy-to-stage:
      stage: staging
      rules:
        - except: manual
      script:
        -..........