Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger only specific stage of pipeline with gitlab API?

I have gitlab project with ci file:

stages:
 - build
 - run

build:
  stage: build
  script:
    - (some stuff)
  tags:
    - my_runner_tag
  except:
    - triggers
  when: manual

run:
  stage: run
  script:
    - (some stuff)
  tags:
    - my_runner_tag
  except:
    - triggers
  when: manual

Jobs are created on every source code change, and they can be run only manually, using gitlab interface. Now, i want to have possibility to trigger stage run with Gitlab API. Trying:

curl -X POST \
>      -F token=xxxxxxxxxxxxxxx \
>      -F ref=master \
>      https://gitlab.xxxxx.com/api/v4/projects/5/trigger/pipeline

Returns:

{"message":{"base":["No stages / jobs for this pipeline."]}}

Seems, like i have to define stage to trigger, but i can't find a way to pass it via api call.

like image 989
coolsv Avatar asked Oct 28 '25 14:10

coolsv


1 Answers

you are using the wrong endpoint, to do it, you need to follow the path below

  1. list all of your pipelines and get the newest one GET /projects/:id/pipelines

  2. list the jobs from this pipeline GET /projects/:id/pipelines/:pipeline_id/jobs

  3. After that you can trigger your job POST /projects/:id/jobs/:job_id/play

like image 191
Sergio Tanaka Avatar answered Oct 30 '25 14:10

Sergio Tanaka