gitlab-plugin
gitlab-plugin copied to clipboard
Show stages in Gitlab, possible?
I'm testing out Jenkins declarative pipeline and I have a (multi-branch pipeline) job that builds successfully, however I would like it to show the stages in Gitlab, but I'm not sure how to do so (if it's even possible).
Here's what I mean:
I would like it to look something like this:

But so far, I get something like this:

This is my code so far:
#!/usr/bin/env groovy
// TEST FLAG - to make it easier to turn on/off unit tests for speeding up access to later stuff.
def runTests = true;
def testFlag = runTests ? '-Dmaven.test.failure.ignore=true' : '-DskipTests';
// Define common variables that will be used throughout this file.
def version() {
def matcher = readFile('pom.xml') =~ '<version>(.+)</version>'
matcher ? matcher[0][1] : null
}
// AAId = Application Artifact Id
def AAId() {
def matcher = readFile('pom.xml') =~ '<artifactId>(.+)</artifactId>'
matcher ? matcher[0][1] : null
}
def running(gitlabBuildName) {
updateGitlabCommitStatus(name: "${gitlabBuildName}", state: 'running')
}
def success(gitlabBuildName) {
updateGitlabCommitStatus(name: "${gitlabBuildName}", state: 'success')
}
def failure(gitlabBuildName) {
updateGitlabCommitStatus(name: "${gitlabBuildName}", state: 'failed')
}
properties ([
[$class: 'GitLabConnectionProperty', gitLabConnection: 'Gitlab'],
pipelineTriggers([[
$class: "GitLabPushTrigger",
triggerOnPush: true,
triggerOnMergeRequest: true,
// triggerOpenMergeRequestOnPush: "both",
// triggerOnNoteRequest: true,
// noteRegex: "REBUILD!",
// skipWorkInProgressMergeRequest: true,
// ciSkip: false,
// setBuildDescription: true,
// addNoteOnMergeRequest: true,
// addCiMessage: true,
// addVoteOnMergeRequest: true,
// acceptMergeRequestOnSuccess: true,
branchFilterType: "All",
// targetBranchRegex: "master",
// includeBranchesSpec: "master",
// excludeBranchesSpec: ""
]])
]);
pipeline {
// The following configures the GitLab connection and triggers the job on a push to GitLab.
agent any
options {
gitLabConnection('Gitlab');
timeout(time: 1, unit: 'HOURS'); // Time out for the pipeline
}
tools {
maven 'Maven 3.3.9'
}
environment {
APPLICATION_NAME = 'OrientDB Monitoring';
CREDENTIALS_ID = 'e379691b-fb37-4512-be0a-c246340e8b41';
MAVEN_NAME = 'Maven 3.3.9';
ORIENTDB_HOSTNAME = '10.96.15.0';
ORIENTDB_USER = 'user';
ORIENTDB_PASS = 'pass';
}
stages {
stage( 'Checkout SCM' ) {
agent {
node {
label 'jdk8-maven3'
}
}
options {
gitlabCommitStatus(name: 'Checkout');
}
steps {
checkout(changelog: true, poll: true,
scm: [$class: 'GitSCM', branches: [[name: '**']],//[[name: "origin/${env.gitlabSourceBranch}"]],
browser: [$class: 'GitLab', repoUrl: 'https://git.company.com', version: '9.1'],
doGenerateSubmoduleConfigurations: false,
// Delete workspace before the job starts.
extensions: [[$class: 'WipeWorkspace']],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: "${CREDENTIALS_ID}",
name: 'origin', refspec: '+refs/pull/*:refs/remotes/origin/*',
url: '[email protected]:developer-services/sample-pipeline.git']]
}
}
// Now build the application.
stage( "Build application" ) {
agent {
node {
label 'jdk8-maven3'
}
}
steps {
gitlabBuilds(builds: ["Build", "Code quality"]) {
running('Build');
sh "mvn -Pdebug -U clean install ${testFlag} -V -B"
}
}
post {
success {
running('Code quality');
// Test code quality and send results to SonarQube.
withSonarQubeEnv('Sonar') {
sh "mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar"
}
success('Build');
success('Code quality');
}
failure {
failure('Build');
failure('Code quality');
}
}
}
// Run application to test it out.
stage("Test compiled application") {
agent {
node {
label 'jdk8-maven3'
}
}
steps {
script {
def appArtifactId = AAId()
def appVersion = version()
def workspace = pwd()
sh( "java -DHOSTNAME=${ORIENTDB_HOSTNAME} -DUSERID=${ORIENTDB_USER} -DPASSWORD=${ORIENTDB_PASS} -jar ${workspace}/target/${appArtifactId}-${appVersion}.jar" );
}
}
}
}
}
Any help is kindly appreciated!
Did you solve this? Having the same issue :/
@langerhans: Unfortunately, I couldn't resolve the issue, and had to resort to installing "Blue Ocean" plugin.
Gitlab responded back to me and the response was extremely disappointing... This is what they said:
Hello Fadi,
If the Jenkins integration is not working, we will try to provide support here.
But what you are mentioning is a feature request, which we can usually help facilitate since you are an EE customer.
However, in this specific case, you are likely to be disappointed if you spend the time on drafting the feature request, answer a few questions in the comments, and check back periodically for progress. GitLab's direction has been to spend all of our CI team's development efforts on GitLab CI, which is gaining popularity very fast. Because of how fast GitLab CI is gaining popularity, I do not see us pulling developers off GitLab CI to work on the Jenkins plugin.
We will continue to provide an open API so that the community can keep creating things like that Jenkins plugin, and we know that many of our users depend on Jenkins, so it is a high priority to us that it keeps working. So you can use it in production without any worries that we could drop support for it, but if you are needing a tighter integration with GitLab, our own CI is currently the only option.
I am sorry to be the bearer of bad news, this is certainly not what you wanted to hear. Thank you for understanding.
De Wet Blomerus Service Engineer | GitLab Inc.
Sorry, i just hit the wrong button :-/ For what it's worth I was just commenting that we could try and see whether supporting the Gitlab CI API would make this work - but a) this seems to be a major undertaking (because registering a "Jenkins runner" in Gitlab is quite different from letting Gitlab trigger a build via a webhook) and b) it could well be that Gitlab requires that the pipeline's description resides in its .gitlab-ci.yml to recognize the right order of the stages. So i just wanted to cancel my comment. Sorry again!
Thank you @farahfa , this is indeed a disappointing result. Maybe it was a misinterpretation on their side, but I wouldn't even want them to work on the Jenkins plugin but merely extend their Commit Status API to allow an extended description of what pipeline the status we send corresponds to. This should be a simple enough request imho. GitLab CI just doesn't cut it for my use case yet (large Android project). We make use of a lot of Jenkins plugins that provide functionality GitLab CI doesn't. I understand their view of the business perspective but it seems kinda short sighted to think they will be the "single point of dev workflow" for all their customers.
GitLab is working to find a long-term solution. There is some discussion in https://gitlab.com/gitlab-org/gitlab-ce/issues/34550. We understand the importance of continued, stable Jenkins integration and will figure out a way to make it happen, in coordination with this community.
To the question of the issue creator, at the moment it is not possible to post some stage names to GitLab:
https://docs.gitlab.com/ee/api/commits.html#post-the-build-status-to-a-commit
https://github.com/gitlabhq/gitlabhq/blob/604db40bbe8dfcef846360e459345313dfd4020b/lib/api/commit_statuses.rb
@CSchulz, Well yeah we got that already; check the second comment
Oh I read the discussion and forget about it. 😄
So we have to provide an own merge request or wait for someone else doing it.
After it the feature can be implemented here.
Has there been any update on this?
any updates?
any updates?
No
I've been able to track individual stages using the gitlabCommitStatus action, and the gitLabConnection/gitlabBuilds options (docs available in the pipeline steps helper).
However, the steps are listed independently, with no relationship between one and another. It's useful, but not to the extent that the OP would like.
Still, it's better than nothing.
This is how I did it (high-level example):
def buildInfo = [
projectId: "project/path/in/gitlab",
revisionHash: "commit-hash-or-branch-or-tag-name"
];
pipeline
{
agent any
options
{
// This name is defined in the System configurations
gitLabConnection("My GitLab Connection")
// Use the list of build stages you'll track below
gitlabBuilds(builds: [
"Checkout",
"Compile",
"Deploy",
])
}
stages
{
stage("Checkout")
{
steps
{
gitlabCommitStatus(name: STAGE_NAME, builds: [ buildInfo ])
{
checkout scm;
}
}
}
stage("Compile")
{
steps
{
gitlabCommitStatus(name: STAGE_NAME, builds: [ buildInfo ])
{
// compile ...
}
}
}
stage("Deploy")
{
steps
{
gitlabCommitStatus(name: STAGE_NAME, builds: [ buildInfo ])
{
// deploy ...
}
}
}
}
}
I'll probably keep this since it's useful for visibility in GitLab.
Cheers!