Gitee Jenkins Plugin is a Jenkins Plugin developed by Gitee based on GitLab Plugin. It is used to configure Jenkins trigger, accept WebHook trigger Jenkins sent by Gitee platform for automatic continuous integration or continuous deployment, and can feed back the build status to Gitee platform.

Introduction to the

Currently supported features:

  • When pushing code to Gitee, the configured WebHook triggers the Jenkins task to build.
  • Comment commit record triggers commit record corresponding to version Jenkins task build
  • When submitting Pull Request to Gitee project, Jenkins task will be triggered by configured WebHook to build, supporting PR actions: create, update, accept, close, review pass, test pass.
  • Supports [Ci-skip] instruction filtering or [Ci-build] instruction triggering builds.
  • Filter the Commit version that has been built, if the branch Push is filtered, then the same branch Push is filtered, if the PR is filtered, then the same PR is filtered.
  • Filter triggers by branch name.
  • The regular expression filters the branches that can be triggered.
  • Set the WebHook authentication password.
  • Post-build operations can configure pr-triggered build results to comment to the PR corresponding to Gitee.
  • Post-build operations Can be configured PR can be automatically merged after a successful build triggered by PR.
  • For all EVENTS related to PR, if PR code conflicts cannot be merged automatically, the build will not be triggered; If the comment to PR function is configured, a comment to PR conflict is displayed.
  • PR reviews can trigger builds via WebHook (can be used for PR trigger build failures to facilitate re-triggering builds from Gitee platform reviews)
  • Support for configuring PR does not require filtering to trigger builds when testing is required. (Can be used to not build a deployment test environment without testing)
  • Support for the same PR trigger build, cancel the ongoing incomplete build, the current build (the same PR build does not queue, multiple different PR builds still need to queue)

Planned features

  1. PR reviews and tests through trigger builds (user-triggered deployment and workflow improvements with automatic PR merge features).
  2. Select trigger mode to automatically add WebHook to Gitee.

Plug-in installation

  1. Online installation

    • Go to Manage Jenkins -> Manage Plugins -> Available
    • Enter Gitee in Filter on the right
    • Check Gitee from the optional list below (if Gitee is not in the list, click Check Now to update the plugin list)
    • Click Download Now and Install After restart

  1. Manual installation

    • Go to the latest release from the Release list and download the corresponding xxx.hpi file
    • Go to Manage Jenkins -> Manage Plugins -> Advanced
    • Select XXX. Hpi from the Upload Plugin File and click Upload
    • Select Restart Jenkins when installation is complete and no jobs are running

The plug-in configuration

Add Gitee link configuration

  1. Go to Jenkins -> Manage Jenkins -> Configure System -> Gitee Configuration -> Gitee Connections

  2. Enter Gitee or whatever name you want in Connection Name

  3. Enter the full URL of Gitee in the Gitee host URL: https://gitee.com (domain name for deployment entered by Gitee private customers)

  4. If Gitee APIV5 private token is not configured in Credential, click Add – > Jenkins

    1. DomainchooseGlobal credentials
    2. KindchooseGitee API Token
    3. ScopeChoose the range you need
    4. Gitee API TokenEnter your Gitee private token to get the address:Gitee.com/profile/per…
    5. ID.DescripitonEnter the ID and description you want.
  5. The Credentials select the configured Gitee APIV5 Token

  6. Click Advanced to configure whether to ignore SSL errors (depending on your Jenkins environment) and set link test timeout (depending on your network environment).

  7. Click Test Connection to Test whether the link is successful. If it fails, please check steps 3, 5 and 6 above.

After successful configuration, the following figure is shown:

New Build Task

Go to Jenkins -> New Item, type ‘Gitee Test’ for name, select Freestyle Project and save to create the build project.

Task global Configuration

Select the Gitee link from the previous step in task global configuration. Go to Configure -> General, Gitee Connection for a task (e.g. ‘Gitee Test’) and select the previously configured Gitee link as shown:

Source management configuration

Go to the Configure -> Source Code Management TAB for a task such as ‘Gitee Test’

  1. Click on the Git

  2. Enter your repository address, such as [email protected]:gitee_group/gitee_project.git

    1. Click on theAdvancedButton,NameFieldorigin.RefspecField input+refs/heads/*:refs/remotes/origin/* +refs/pull/*/MERGE:refs/pull/*/MERGE, note that the new Jenkins no longer accepts multiple refS descriptions containing * wildcards. For example, only the first half can be written for push trigger, and only the second half can be written for PR trigger. See the following figure for details:
  3. In the Credentials field, enter the user name and password Credentials corresponding to the HTTPS address of the Git repository or the SSH key Credentials corresponding to SSH. Note that Gitee API Token Credentials cannot be used for source management. API call credentials for the Gitee plug-in only.

  4. Branch Specifier options:

    1. For single warehouse workflow input:origin/${giteeSourceBranch}
    2. For PR workflow input:pull/${giteePullRequestIid}/MERGE
  5. Additional changes

    1. For the single repository workflow, if you want to merge the default branch (published branch) before the pushed branch is built, you can do the following:

      1. Click on theAddA drop-down box
      2. chooseMerge before build
      3. Set up theName of repositoryorigin
      4. Set up theBranch to merge to${ReleaseBranch}The default branch that you want to merge (publish branch)
    2. For the PR workflow, the Gitee server already pre-merges the original and target branches of PR, so you can build directly, or if the target branch is not the default branch (the release branch), you can also do a pre-build merge.

The configuration is shown in the figure below:

Trigger configuration

Go to the trigger Build for the task configuration: Configure -> Build Triggers TAB

  1. Enabled Gitee Triggers triggers the build triggering rule that you need, such as Push Event,Opened Merge Request Events, which accepts Webhooks and triggers the build. Currently, the following events are supported:

    • Push Events: Push code Events
    • Commit Comment Events: Record Comment Events
    • Opened Merge Request Events: Sends PR Events
    • Updated Merge Request Events: Updates PR Events
    • Accepted Merge Request Events: Accepts/merges PR Events
    • Closed Merge Request Events: Closes PR Events
    • Approved Pull Requests: Reviewed PR events that passed
    • Tested Pull Requests: The PR event was Tested
  2. Build Instruction Filter:

    • NoneNo filter:
    • [ci-skip] skip build: commit message or PR Indicates yes[ci-skip], skip the build trigger.
    • [ci-build] trigger build: commit message or PR Indicates yes[ci-build], triggers the build.
  3. Ignore Last commit has build This option can skip commit builds that have already been built.

  4. Cancel Incomplete build on same Pull Requests Cancel incomplete build on same Pull Requests Cancel incomplete build on same Pull Requests Cancel incomplete build on same Pull Requests Cancel incomplete build on same Pull Requests Cancel incomplete build on same Pull Requests Cancel incomplete build on same Pull Requests Cancel incomplete build on same Pull Requests

  5. Ignore Pull Request Conflicts this option selects whether to build based on PR conflicts when A PR triggers a build.

  6. Allowed Branches You can configure branches that are Allowed to be built. Currently, branch names and regular expressions are supported for filtering.

  7. Secret Token for Gitee WebHook This option allows you to configure a WebHook password. The password must be the same as the password configured for Gitee WebHook to trigger the build.

  8. Note: If the PR state is not auto-merge, the build is not triggered.

Post-build step configuration

Go to the post-build configuration for the task configuration: Configure -> post-Build Actions TAB

Build results are reviewed back to Gitee

  1. Click the Add Post-Build Action drop-down box and select Add Note with Build status on Gitee pull requests

  2. You can configure the following parameters in Advanced:

    • Add message only for failed builds: Comment back to Gitee only for build failures
    • Customize the feedback content of each state (the content can refer to Jenkins’ environment variable or custom environment variable)
  3. If enabled, states that are not automatically merged can also be commented back to Gitee

Build automatic merge PR successfully

Click the Add post-build Action drop-down box and select Accept Gitee pull Request on success

New Gitee project WebHook

Go to the Gitee project set in the source control configuration and go to Administration -> WebHooks

  1. Add WebHook, FILL in URLTrigger configuration: Build when a change is pushed to Gitee. Gitee webhook URLThe URL shown in:http://127.0.0.1:8080/jenkins/project/fu
  2. Password: The WebHook password configured in point 5 of trigger configuration
  3. Check PUSH, Pull Request

Test push triggers the build

  1. In the WebHook management of Gitee, select the WebHook click test of PUSH to observe the construction status of Jenkins task
  2. The Gitee project page edited a file submission and observed the build status of the Jenkins task

Test PR triggers the build

  1. In the WebHook management of Gitee, the WebHook click test of Pull Request was selected to observe the construction status of Jenkins task
  2. Create a Pull Request in the Gitee project and observe the build status of the Jenkins task