ndp
ndp

Reputation: 893

Programmatically get the result of a GitlabCI Job

I'm trying to create a script which takes the result of a CI job and if it succeeded launches some other testing on that repository.

The problem is that gitlab api doesn't support getting the Job's output. Let alone a success/failure flag. I tried to use webdriver to get the content of the <div> containing the results. However, the urls leading to the jobs aren't incremental in a predictable way. It depends on how many jobs exist overall and where in the queue this job has been placed. Here's an example how such a job url looks like

http://<glab_url>/<user>/<project>/-/jobs/25

25 being the overall job id

The other idea is to make webdriver click through the UI until we get to the specified job, however this seems inefficient.

Has anybody faced this problem before? If so how did you solve it?

//edit: Providing some context after @vladkras's useful answer. // We have multiple dev teams, devs are encouraged to create their own projects. I don't have any control over who runs what in a CI. I just want to add some basic checks for security, known bad patterns and secrets in repos that build successfully. These checks should just report to me/my team for now and if the project succeeds then we will discuss about bothering developers into integrating it.

Upvotes: 0

Views: 3352

Answers (1)

vladkras
vladkras

Reputation: 17228

The problem is in your architecture. If you need "to do something when pipeline succeed" - just add it as one more job. It will never run if previous one fails.

And you can use dependencies to access result of previous job, e.g.:

job1:
  artifacts:
    paths:
     - test
  script:
   - echo "result" > test/file
job2:
  dependencies:
    job1
  script:
   - cat test/file

EDIT

API solution how to get all CI pipelines and jobs that succeeded:

GET /projects

GET /projects/:id/pipelines?status=success

GET /projects/:id/jobs?scope[]=success

Upvotes: 3

Related Questions