Start job automatically if previous, manually started job succeeds

Hey, i have trouble getting this simple workflow to work. I have a DAG pipeline consisting of three stages

- config
- build
- deploy

Now the config stage is triggered manually using the

config:myservice:
  ...
  when: manual

keyword inside the pipeline definition. The next job in stage “build” should automatically be run as soon as “config” was successfully done.
Therefore i tried this in the build-job:

build:myservice:
  stage: build
  needs:
    - config:myservice
  when: on_success

But this will always trigger the build, no matter of the outcome of the config-job!

Looks like others had this problem as well, but did not came up with an solution?

Hm, i somehow get such a behaviour by adding “allow_failure: false” to the config-job:

config:myservice:
  ...
  when: manual
  allow_failure: false

Hi,

I’m not sure whether I had understood your desired outcome yet.

Let’s assume you have 3 jobs each in a stage.
Your config-job should only start manually, and the next job in the next stage should only start when the config-job was successful.

If you scale that up, you would need to use needs.

build1 needs config1
build2 needs config2
build3 needs config3

The pattern would have to be repeated because if it was missing, build4 would wait until everything in stage config was finished.

stages:
    - config
    - build
    - deploy



my-config-1:
    stage: config
    script:
        - exit 0
    when: manual

my-config-2:
    stage: config
    script:
        - exit 0
    when: manual

my-config-3:
    stage: config
    script:
        - exit 0
    when: manual



my-build-1:
    needs: ["my-config-1"]
    stage: build
    script:
        - exit 0

my-build-2:
    needs: ["my-config-2"]
    stage: build
    script:
        - exit 0

my-build-3:
    needs: ["my-config-3"]
    stage: build
    script:
        - exit 0



my-deploy-1:
    needs: ["my-build-1"]
    stage: deploy
    script:
        - exit 0

my-deploy-2:
    needs: ["my-build-2"]
    stage: deploy
    script:
        - exit 0

my-deploy-3:
    needs: ["my-build-3"]
    stage: deploy
    script:
        - exit 0

You can see my output here:

As you can see, if I trigger my-config-1 my-build-1 starts automatically afterward. And after that my-deploy-1.

1 Like

With my “solution” i now have the problem that if a job should be startable manually on an later stage, it is “blocked”:

stages:
  - config
  - build
  - deploy
...
build:job-without-config:
  stage: build
  when: manual

It was used to work this way, but now it looks like without a job in the earlier stage (config) the build stage seems blocked.

Hmm, I’m still not 100% sure what you really want. Sorry :smiley:

I think you got blocked jobs of allowed_failed: false

You can use allow_failure: false with a manual job to create a blocking manual job. A blocked pipeline does not run any jobs in later stages until the manual job is started and completes successfully.


If we stick to my example:

without needs:

You see, if we take away the needs you could either start my-config-1 or my-build-1 which I think is not what you want, right?

Edit:

To make the changes more clear:

my-config-1:
    stage: config
    script:
        - exit 0
    when: manual

my-build-1:
    # needs: ["my-config-1"]
    stage: build
    script:
        - exit 0
    when: manual  # added

However as far I understood you now. You want 2 things.

  • config -> build -> deploy
  • build -> deploy

On the second approach you don’t want config to run, right? Then you would need to rules:if.
However, you would then have to somehow define when things are executed with config and when they are not.

1 Like

You got it nearly, thanks! Primarily i want to manually start a “config” job, which should, if successfull, kickoff the following build stage job. The deploy stage should be triggered manually again, also only if build was successfull.

But, i have some jobs where there is no “config” stage. And those should be started manually.