UPDATE
The script in the answer is obsolete now, since Gitlab plugin for Jenkins can now report build status back to Jenkins.
I'm trying to integrate Gitlab CE 8.4 and Jenkins. I've read that Jenkins CI integration is available in Gitlab EE, but currently its not an option.
I've already set up Jenkins gitlab plugin and Web hooks, and pushes to my repo trigger builds of Jenkins jobs.
However, these builds are not shown in the 'Builds' tab in the respective Gitlab page.
If I commit .gitlab-ci.yml file to the repository, web hooks still work, Jenkins jobs run, but the 'Builds' page shows that the build is stuck, since no runners are defined.
Indeed, I haven't set up any Gitlab CI runners, since they are not related to Jenkins, as far as I understand.
I'd like to keep my Jenkins job since some useful information is published there, and I also would like to have its status on the Gitlab page.
I'm thinking in this regard about a simple script for Gitlab CI runner, that would capture console output from a Jenkins job and translate it to Gitlab. Something like running wget or curl, because Jenkins provides API to see job's output.
However, documentation about Gitlab CI and .gitlab-ci.yml is limited, as well as examples.
How could I write that job file?
Am I right in thinking that Gitlab receives job's stdout?
Best Answer
Yes, Gitlab-CI prints stdout of a job and relates on exit codes.
My solution consists of installed Gitlab-CI runner and the python script, called from
.gitlab-ci.yml
, that gets git commit ID fromCI_BUILD_REF
environment variable, connects to the Jenkins host, finds respective build console, reads the output viaurllib2.urlopen(...).readlines()
, and prints it to stdout.It uses
bySHA1
url, provided by the Jenkins Git plugin, to find the build console.The script also looks for the line, starting with the word
Finished:
and exits with the exit code, according to what follows that word: 0 if it isSUCCESS
, and 1 ifFAILURE
, orUNSTABLE
.Script text:
And in addition,
.gitlab-ci.yml
:Drawbacks are obvious: pressing cancel button actually cancels the translation, not the Jenkins job, no clickable links to the Jenkins job page.
At least it informs about Jenkins job statuses.
UPDATE. This script does not authorize to Jenkins, it assumes relaxed security setting, when everyone can see job output.
UPDATE2. Jenkins-Gitlab plugin can now report build status back to Gitlab, which obsoletes this script.