jenkinsci / jenkinsci/gitlab-plugin

Declarative GitLab Stages Syntax

Open
#1,039 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
1.4k
Forks
615
Avg merge
4h 32m
Merged PRs (30d)
10

Description

I am working on moving from scripted pipelines to declarative pipelines. One of the issues is GitLab integration.

As of right now, at least according to the `README`, this is the only option:

```
pipeline {
post {
failure {
updateGitlabCommitStatus name: 'build', state: 'failed'
}
success {
updateGitlabCommitStatus name: 'build', state: 'success'
}
}
[...]
}
```

This doesn't give you the same granularity as we currently have with the scripted pipeline. When we define the stages, we execute:

updateGitlabCommitStatus name: stageName, state: 'pending'

And when the stage finishes we execute:

updateGitlabCommitStatus name: stageName, state: 'success'

or

updateGitlabCommitStatus name: stageName, state: 'failed'

depending on result.

This means that the status of each stage is reported to GitLab.

I was hoping to have the same functionality when using declarative pipelines and I have a proposal for how to accomplish it:

```
pipeline {
agent any
options {
gitLabConnection('your-gitlab-connection-name')
gitLabStages(enabled: true) // <-------------------- Just add this option.
}
triggers {
gitlab(triggerOnPush: true, triggerOnMergeRequest: true, branchFilterType: 'All')
}
stages {
stage("build") {
steps {
echo "hello world"
}
}
}
[...]
}
```

I never wrote a Jenkins plugin and I know little about how Jenkins works internally, but if they offer callbacks or events for when a stage is defined and when a stage finishes, it should be possible for the GitLab Plugin to offer this functionality. I would be happy to submit a PR, but I quite frankly haven't been able to find any relevant documentation on how to implement something like that. So I'm raising an issue, hoping that someone else might know if and how this would be possible.

I'm guessing that [github-autostatus-plugin](https://github.com/jenkinsci/github-autostatus-plugin) might be doing something like that. I had a look, but that plugin is around 10k lines of code, so it's a bit difficult to figure out where to start. Any help or advice would be appreciated.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.