doc/integration/jenkins.md
{{< details >}}
{{< /details >}}
{{< history >}}
{{< /history >}}
Jenkins is an open source automation server that supports building, deploying and automating projects.
You should use a Jenkins integration with GitLab when:
This integration can trigger a Jenkins build when a change is pushed to GitLab.
You cannot use this integration to trigger GitLab CI/CD pipelines from Jenkins. Instead, use the pipeline triggers API endpoint in a Jenkins job, authenticated with a pipeline trigger token.
After you have configured a Jenkins integration, you trigger a build in Jenkins when you push code to your repository or create a merge request in GitLab. The Jenkins pipeline status displays on merge request widgets and the GitLab project's home page.
<i class="fa-youtube-play" aria-hidden="true"></i> For an overview of the Jenkins integration for GitLab, see GitLab workflow with Jira issues and Jenkins pipelines.
To configure a Jenkins integration with GitLab:
Create a personal, project, or group access token.
Set the access token scope to API.
Copy the access token value to configure the Jenkins server.
Install and configure the Jenkins plugin to authorize the connection to GitLab.
gitlab-plugin and select it to install.
See the Jenkins GitLab documentation
for other ways to install the plugin.For more information, see Jenkins-to-GitLab authentication.
Set up the Jenkins project you intend to run your build on.
If you created a freestyle project, in the Post-build Actions section, choose Publish build status to GitLab.
If you created a pipeline project, you must use a Jenkins Pipeline script to update the status on GitLab.
Example Jenkins Pipeline script:
pipeline {
agent any
stages {
stage('gitlab') {
steps {
echo 'Notify GitLab'
updateGitlabCommitStatus name: 'build', state: 'pending'
updateGitlabCommitStatus name: 'build', state: 'success'
}
}
}
}
For more Jenkins Pipeline script examples, see the Jenkins GitLab plugin repository on GitHub.
Configure the GitLab integration with Jenkins in one of the following ways.
You should use this approach for Jenkins integrations if you can provide GitLab with your Jenkins server URL and authentication information.
If you cannot provide GitLab with your Jenkins server URL and authentication information, you can configure a webhook to integrate GitLab and Jenkins.
https://JENKINS_URL/project/YOUR_JOB).Connection failed. Please check your settingsWhen you configure GitLab, you might get an error that states Connection failed. Please check your settings.
This issue has multiple possible causes and solutions:
| Cause | Workaround |
|---|---|
| GitLab is unable to reach your Jenkins instance at the address. | For GitLab Self-Managed, ping the Jenkins instance at the domain provided on the GitLab instance. |
| The Jenkins instance is at a local address and is not included in the GitLab installation's allowlist. | Add the instance to the GitLab installation's allowlist. |
| The credentials for the Jenkins instance do not have sufficient access or are invalid. | Grant the credentials sufficient access or create valid credentials. |
The Enable authentication for /project end-point checkbox is not selected in your Jenkins plugin configuration | Select the checkbox. |
Could not connect to the CI serverYou might get an error that states Could not connect to the CI server in a merge
request if GitLab did not receive a build status update from Jenkins through the
Commit Status API.
This issue occurs when Jenkins is not properly configured or there is an error reporting the status through the API.
To fix this issue:
This issue might occur when the request exceeds the webhook timeout limit, which is set to 10 seconds by default.
For this issue, check:
The integration webhook logs for request failures.
/var/log/gitlab/gitlab-rails/production.log for messages like:
WebHook Error => Net::ReadTimeout
or
WebHook Error => execution expired
On GitLab Self-Managed, you can fix this issue by increasing the webhook timeout value.
To troubleshoot an integration issue, you can enable job logs in Jenkins to get more details about your builds.
To enable job logs in Jenkins:
com.dabsquared.gitlabjenkins.To view your logs: