Setting up automated plugin release

View the index of available developer guides

Continuous Delivery of Jenkins Components and Plugin (JEP-229) is relatively new. Any feedback from early adopters will be appreciated.

Introduction

Maintainers of Jenkins plugin repositories on GitHub can opt into continuous delivery (CD). In this mode, every successful build of the default branch (master or main) by ci.jenkins.io results in a new plugin release. GitHub Actions are used to rebuild the code and deploy it to Artifactory, without the need for maintainers to use personal credentials or local builds. Release notes are generated automatically according to pull request (PR) titles and some predefined labels.

maven-release-plugin (MRP) is not used in this mode. Rather than traditional version numbers like 1.23 or 2.3.4 which are chosen by the maintainer, a CD release will have a version of the form 123.vabcdef456789: an integer component determined by the Git history depth, and an informational component with the Git commit hash.

Checklist

Incrementals Enablement

Verify that the plugin has already been incrementalified. pom.xml should contain <version>${revision}${changelist}</version> before proceeding with subsequent steps.

A new plugin created from the archetypes will already have this setup.

Enable CD Permissions

Enable the continuous delivery flag in repository permission updater (RPU) for your plugin by filing a pull request adding to permissions/plugin-xxx.yml:

cd:
  enabled: true

Once that has been merged, start checking https://github.com/jenkinsci/your-plugin/settings/secrets/actions until you see MAVEN_TOKEN and MAVEN_USERNAME appear under Repository secrets.

Configure Release Drafter

Create or update .github/release-drafter.yml to contain only:

_extends: .github

Make sure to remove any tag-template override that may have been configured previously.

Delete .github/workflows/release-drafter.yml if you previously enabled Release Drafter using the GitHub Actions, or remove the App from the repository if it was configured that way.

These files may have been set up this way by the plugin archetype that you used to initialize the plugin.

Configure CD Workflow

Create .github/workflows/cd.yaml as a copy of the cd.yaml template.

Configure Dependabot (optional)

If you have a .github/dependabot.yml, add:

- package-ecosystem: github-actions
  directory: /
  schedule:
    interval: weekly

If you did not yet have such a file, create it now. For example:

version: 2
updates:
- package-ecosystem: maven
  directory: /
  schedule:
    interval: weekly
- package-ecosystem: github-actions
  directory: /
  schedule:
    interval: weekly

Update Maven POM and Config

Update the file .mvn/maven.config so it looks like this:

-Pconsume-incrementals
-Pmight-produce-incrementals
-Dchangelist.format=%d.v%s

Update the Maven pom.xml as described below, depending on your preferred version number format.

Once you’re done with these changes, commit all of the source file changes in a branch and file a pull request for them. Do not forget to git add . to make sure any newly created files are included. Merge this PR activating CD. Be sure to apply one of the predefined labels to this and every subsequent PR before merging so that Release Drafter can properly categorize changes.

Fully automated versioning

For a regular component whose version number is not that meaningful, let the version number be automatically determined by setting a top-level <version>${changelist}</version> and having an entry <changelist>999999-SNAPSHOT</changelist> in the <properties> section, removing <revision>:

--- a/.mvn/maven.config
+++ b/.mvn/maven.config
@@ -1,2 +1,3 @@
 -Pconsume-incrementals
 -Pmight-produce-incrementals
+-Dchangelist.format=%d.v%s
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
-    <version>${revision}${changelist}</version>
+    <version>${changelist}</version>
     <packaging>hpi</packaging>
@@ -26,8 +26,7 @@
     <properties>
-        <revision>1.23</revision>
-        <changelist>-SNAPSHOT</changelist>
+        <changelist>999999-SNAPSHOT</changelist>
         <jenkins.version>2.176.4</jenkins.version>
     </properties>

In this typical case, a CI/release build (-Dset.changelist specified) will be of the form 123.vabcdef456789. A snapshot build will be 999999-SNAPSHOT: arbitrary but treated as a snapshot by Maven and newer than any release.

Note that you will very quickly create releases with version numbers greater than 100, as the major version component corresponds to the number of commits in the branch you’re releasing from. If you’re not ready to commit to all future versions of your plugin being this large, see the next option.
It is worth communicating this to your users, as they will see a very different version number format than before. The best way to do this is to add a line to the release notes: example note.
Manually controlled prefix

If you do not want to have (major) version numbers increase quickly, like with fully automated versioning described above, keep <revision> in the <properties> section, setting it to the prefix (major, major.minor, etc., depending on how much of the version number you want to manually manage) and use it as part of the top-level <version> element:

--- a/.mvn/maven.config
+++ b/.mvn/maven.config
@@ -1,2 +1,3 @@
 -Pconsume-incrementals
 -Pmight-produce-incrementals
+-Dchangelist.format=%d.v%s
--- a/pom.xml
+++ b/pom.xml
@@ -10,12 +10,12 @@
   <artifactId>some-library-wrapper</artifactId>
-  <version>${revision}${changelist}</version>
+  <version>${revision}.${changelist}</version>
   <packaging>hpi</packaging>
   <properties>
-    <revision>1.2.3</revision>
-    <changelist>-SNAPSHOT</changelist>
+    <revision>1</revision>
+    <changelist>999999-SNAPSHOT</changelist>
     <jenkins.version>2.176.4</jenkins.version>

Here the version numbers will look like 1.321.vabcdef456789 or 1.999999-SNAPSHOT, respectively, which are more similar to version numbers used by Jenkins itself.

It is not recommended to implement actual semantic versioning with automated releases performed by CD, as that requires great care in always changing the revision as part of the changes that semantically would require a revision change for the next release. Otherwise, automated releases may have version numbers that semantically would not make sense.
Versioning with wrapped components

Similar to the previous option, for a component whose version number ought to reflect a release version of some wrapped component, use a hyphen (-) as the separator between the prefix corresponding to the wrapped component’s version and the CD-generated suffix:

--- a/.mvn/maven.config
+++ b/.mvn/maven.config
@@ -1,2 +1,3 @@
 -Pconsume-incrementals
 -Pmight-produce-incrementals
+-Dchangelist.format=%d.v%s
--- a/pom.xml
+++ b/pom.xml
@@ -10,12 +10,12 @@
   <artifactId>some-library-wrapper</artifactId>
-  <version>${revision}${changelist}</version>
+  <version>${revision}-${changelist}</version>
   <packaging>hpi</packaging>
   <properties>
-    <revision>4.0.0-1.3</revision>
-    <changelist>-SNAPSHOT</changelist>
+    <revision>4.0.0</revision>
+    <changelist>999999-SNAPSHOT</changelist>
     <jenkins.version>2.176.4</jenkins.version>

Here the version numbers will look like 4.0.0-123.vabcdef456789 or 4.0.0-999999-SNAPSHOT, respectively. Use the revision property for the <dependency> declaration to ensure they always match:

<dependency>
    <groupId>org.elsewhere</groupId>
    <artifactId>some-lib</artifactId>
    <version>${revision}</version>
</dependency>

Releasing

Now whenever Jenkins reports a successful build of your default branch, and at least one pull request had a label indicating it was of interest to users (e.g., enhancement rather than chore), your component will be released to Artifactory and release notes published in GitHub. You do not need any special credentials or local checkout; just merge pull requests with suitable titles and labels.

You will see a lot of workflow runs in the Actions tab in GitHub, only a small proportion of which are actual releases. Due to technical limitations in GitHub Actions it is not possible to suppress the extraneous runs. Actual releases will display a green check next to the release stage.

You can also trigger a deployment explicitly, if the current commit has a passing check from Jenkins. Visit https://github.com/jenkinsci/your-plugin/actions?query=workflow%3Acd and click Run workflow. If you prefer to only deploy explicitly, not on every push, just comment out the check_run section in the workflow.

Fallback

You can also release manually if you have configured your machine for manual release. To cut a release:

git checkout master
git pull --ff-only
mvn -Dset.changelist \
  -DaltDeploymentRepository=maven.jenkins-ci.org::default::https://repo.jenkins-ci.org/releases/ \
  clean deploy

Troubleshooting

Check that MAVEN_TOKEN and MAVEN_USERNAME appear under Repository secrets.

The upload to the Maven repository fails with "401 Unauthorized"

Unauthorized means that the credentials were invalid, or not sent by Maven.

This normally means that the secrets configured in the repository have expired, create an issue in the INFRA helpdesk on GitHub, and let the team know in #jenkins-infra on Libera Chat.

Alternatively you can temporarily update the secrets yourself with your own personal credentials.

Further troubleshooting help

If none of the provided solutions help, send an email to the Jenkins developers mailing list and explain what you did, and how it failed.

References