mggSoft
mggSoft

Reputation: 1042

GitLab Pipeline error using extends keyword

I got an error on GitLab Pipeline when I commit the next .gitlab-ci.yml for a repository.

Pipeline WorkFlow

stages:
  - build
  - deploy
  - trigger

variables:
    APP_PROJECT_ID: ${CUSTOMER_RELEASED}

build_job:
  stage: build
  tags:
    - dotnet
  script:
    - echo "build"
  only:
    - tags
  allow_failure: false

.deploy_job_base:
  stage: deploy
  needs: [build_job]
  tags:
    - dotnet
  script:
    - echo "deploy"
  dependencies:
    - build_job
  only:
    - tags

deploy_job_sport:
  extends: .deploy_job_base
  after_script:
    - $APP_PROJECT_ID = "2096"
  when: manual
  allow_failure: false

deploy_job_others:
  extends: .deploy_job_base
  after_script:
    - $APP_PROJECT_ID = "0"
  when: manual
  allow_failure: false

.trigger_base:
  stage: trigger
  script:
    - echo "Customer Project ID '{$APP_PROJECT_ID}'"
    - echo "Call API..."

trigger_sport:
  extends: .trigger_base
  needs: [deploy_job_sport]
  
trigger_others:
  extends: .trigger_base
  needs: [deploy_job_others]

Lint status is correct Lint Status but I get that error GitLab Pipeline when I commit changes:

Found errors in your .gitlab-ci.yml: 'trigger_sport' job needs 'deploy_job_sport' job but 'deploy_job_sport' is not in any previous stage 'trigger_others' job needs 'deploy_job_others' job but 'deploy_job_others' is not in any previous stage

If I remove trigger_sport and trigger_others job and create only one job, it works fine but I don't know how I can target the two manual jobs (deploy_job_sport and deploy_job_others) to a single job. Do you have any idea? Thanks in advance.

Upvotes: 0

Views: 2362

Answers (1)

SPMSE
SPMSE

Reputation: 618

I think this is related to the fact that you're using only: tags in your template for deploy jobs and the build job also is limited to run when commits contain a tag.

But the trigger template is missing this limitation which most likely causes this error when pushing a commit without a tag because the pipeline creation would add trigger_XY to the pipeline, which has dependencies to the previous deploy_XY jobs.

When updating your job template for trigger jobs to the following this error should be resolved:

.trigger_base:
  stage: trigger
  script:
    - echo "Customer Project ID '{$APP_PROJECT_ID}'"
    - echo "Call API..."
  only:
    - tags

Upvotes: 1

Related Questions