Pipeline with manual job never terminate

We have a three stages pipeline with one manual job in the second stage. And the third stage needs the second one.

stages:
  - test
  - prepare
  - publish

compile-and-test:
  stage: test
  script:
    - echo "Compile and test"

prepare-artifacts:
  stage: prepare
  script:
    - echo "Prepare and package compiled sources"
  when: manual  

publish-artifacts:
  stage: publish
  needs:
    - prepare-artifacts 
  script:
    - echo "Publishing prepared artifacts" 

With that configuration we are able to manually publish an artifact (more details on https://github.com/gervaisb/gervaisb.github.io/blob/master/Manual_stages_and_dependencies_in_GitLab.md) . However, when we do not trigger the prepare-artifacts job pipeline remains “Running” forever.

How can we terminate the pipeline when the manual job is not triggered ?

A stage in the pipeline executes the commands it’s given in order, when it’s done with all the commands in a stage, it goes to the next one.

One of the commands in your prepare stage never finishes, that’s your problem, sorting that out will solve your problem.

It’s probably just something that’s missing an exit or kill at the end.

It is not one of the command in the “prepare” stage that never finish. It is the manual job itself that is never started. And, because the job never start, the stage never finish and the next one wait for it forever. That’s our issue.

I didn’t read it thoroughly enough, sorry, I pointed to the wrong stage.

My answer still has some relevancy though, as per this article:

The default timeout for all pipelines is 60 minutes (unless otherwise specified), so it should not run forever.

Take our pipeline as an example:

stages:
  - build
  - beta
  - deploy

build:
  stage: build
  image: node
  before_script:
    - npm install
  script:
    - npm run lint
    - npm run jsonlint
    - npm run build
  artifacts:
    paths:
      - dist

beta:
  stage: beta
  image: node:latest
  script:
    - deploy stuff to beta --message="$CI_COMMIT_MESSAGE"
  artifacts:
    paths:
      - dist
  only:
    - master

deploy:
  stage: deploy
  image: node:latest
  only:
      - production
  when: manual
  tags:
      - ourTag
  script:
      - deploy stuff to production --message=$CI_COMMIT_REF_SLUG
  environment:
      name: <snip>/$CI_COMMIT_REF_SLUG

Build runs on all branches, always finishes.
Beta runs on master branch and always finishes.
Deploy is available for manual deployment but only on production branch.

I suggest you replace commands with simple echos to see which of your commands that prevents your pipeline from continuing, cause it always goes to the next thing, but only after it’s finished with the previous one.

Thanks for your answer.

However your manual job (“deploy”) is the last one. While my manual job (“prepare”) is a needed dependency of the “publish” job. And when “prepare” is not executed, “publish” wait for it…

prepare-artifacts:
  # ...
  when: manual  

publish-artifacts:
  # ...
  needs:
    - prepare-artifacts 
  # ...

I copied your pipeline setup to have a look, and now I see the complete extent of your problem.

The problem you’re experiencing stems from the implementation of DAG and the needs command that came with it.

It’s been a registered issue with Gitlab since the August 2019, and they’re still discussing it:

And it’s a little bit sad to say, but your best option is either to set job2 and 3 both as manual, or combine job2 and 3 into the same job until the resolve it, but that might take some time, as it’s a breaking change on pipeline behaviour.

Happy to see that I am not alone with that issue. But sad that I was not able to find it by myself.

Sadly we cannot combine jobs because they are executed on different images or runners.