Setup GitLab Integration¶
CodeMC supports integrating with GitLab for features such as creating new builds on commits or return a build status on Pull requests, commits, etc.
This page tries to explain how you can enable such features.
Setup Automatic Builds¶
CodeMC allows to create new builds whenever commits are done to a connected GitLab Repository. The full steps are available in the GitLab Documentation.
- First, go to your Jenkins Job, and click on the Settings tab.
- Select Build when a change is pushed to GitLab checkbox, then scroll down to the Advanced Tab.
- Once you click on the Advanced Tab, Navigate to the Secret Token Text Box.
- Click on
Generate
, copy the text inside the text bar, and save your Jenkins Configuration. - In your GitLab Project, create a webhook with the trigger url as
https://ci.codemc.io/project/{USERNAME}/{JOB_NAME}
. - Paste the copied token in the Secret Token text bar.
- Test the webhook by pressing the Test Button.
Setup a Commit Status¶
You can add a Commit Status to your repository to display wether a build was successful or not when a commit was made. Full instructions are available on GitLab. To add a Commit status, follow these steps:
- In your Jenkins project, click on the Settings tab.
- Navigate to the Post-build Actions section.
- Upon clicking on Add post-build Action, click on the one titled Publish build status to GitLab.
If you are using a freestyle or Maven project, your process is done. However, if you are using a Pipeline project, continue with the steps below.
- Moving back to your project, create or locate the
Jenkinsfile
inside the root directory. - Inside of the
Jenkinsfile
, create a stage that sets the build status for your project:pipeline { agent any stages { stage('gitlab') { steps { echo 'Notify GitLab' updateGitlabCommitStatus name: 'build', state: 'pending' updateGitlabCommitStatus name: 'build', state: 'success' } } } }