Jenkins Pipeline Shared Library
May 6, 2019 ยท View on GitHub
This repository holds shared library for Jenkins Pipeline
Import Library
The Jenkins library requires sophisticated operation on Jenkins objects, which requires to be setup as Global Pipeline Libraries to avoid extra In-process Script Approval.
Configure Jenkins Pipeline Job
- In The
Manage Jenkins-Configure Systemsection, findGlobal Pipeline Librariesand clickADD.- Give the library a name, for example,
jenkins-library. SetDefault versiontomaster. - For
Retrieval method, chooseModern SCM.- For
Source Code Managementsection, chooseGitHub. - Configure github connection to this repository
- For
- Give the library a name, for example,
Import Library in Jenkinsfile
If you didn't check Load implicitly when configuring the job, you need to use @Library to import it.
In your Jenkinsfile, you can add def lib = library("jenkins-library").org.zowe.jenkins_shared_library on top of the file to import library.
Then you can use any classes/methods defined in the library. For example:
github = lib.scm.GitHub.new(this)
github.init([...])
github.commit('my test')
Run Tests
To start test, run gradle command gradle test.
Generate Documentation
Run gradle command gradle groovydoc to generate documentation.
Relase Process Design
All below scenarios are based on master version v2.3.4 as example, timestamp string example is 20190101000000.
Things We Want to Do
- Allow every branches to publish artifacts for debugging purpose.
- Release is only performed when we want to, so it's always started manually.
Special Notes
- The release stage doesn't have option to choose MINOR/MAJOR/SPECIFIC version bump. Those works should be handled in GitHub with Pull Requests.
- The relase stage doesn't have manual approval option. We assume everything pushed into
masterbranch is for release purpose and have been reviewed by Pull Request reviewers.
Release Options
- For each pipeline, we have 2 build parameters are only available to branches which can do a
release:Perform Release: boolean, default is false.Pre-Release String: string, default is empty. This parameter will only be used ifPerform Releaseis true. This parameter is required if the release is not happened onmasterorv?.x/masterbranch.
- By default, only
master,v?.x/master,stagingandv?.x/stagingbranches can do a release. This can be changed bypipeline.addReleaseBranches(...branches)orpipeline.setReleaseBranches(...branches). - For NPM packages, each branch can have a npm publish tag name when performaing release build. By default,
master's tag islatest,staging's tag isdev. For branches do not have publish tag defined, or branches is not in release build, npm publish will use defaultsnapshottag name, and the version will have normalized branch name included. For example,stagingbranch non-release build will generate a versionv2.3.4-staging-snapshot.20190101000000release onsnapshotnpm tag.stagingbranch release build will generate a versionv2.3.4-dev.20190101000000release ondevtag. And a branchfeature/ltsbuild will generate a versionv2.3.4-feature-lts-snapshot.20190101000000release onsnapshottag. - For pax/zip packages, each branch can also have a release tag name. By default,
master's tag is 'snapshot'. If it's not defined, artifactory publish will use branch name as tag name. For example,masternon-release build will publish artifact tolibs-snapshot-local/org/zowe/<component>/2.3.4-snapshot/and release build will publish tolibs-release-local/org/zowe/<component>/2.3.4/.stagingnon-release build will publish artifact tolibs-snapshot-local/org/zowe/<component>/2.3.4-staging/and release build will publish tolibs-release-local/org/zowe/<component>/2.3.4-rc1/, therc1is the pre-release string which is required.
Pipeline Build Scenarios
- Scenario #1
- Build on
masterwith default parameter values (Perform Release= false,Pre-Release String= empty)- for npm package, it will be published to
npm-local-releaseasv2.3.4-snapshot-master.20190101000000with npm tagsnapshot. - for pax/zip(gradle) package, it will be published to
libs-snapshot-local/org/zowe/<component>/2.3.4-snapshot/as<component>-2.3.4-snapshot.20190101000000.(pax|zip).
- for npm package, it will be published to
- No github tag will be created.
- No version bump will be performed on GitHub.
- Build on
- Scenario #2
- Build on
masterwith (Perform Release= true,Pre-Release String= beta.1)- for npm package, it will be published to
npm-local-releaseasv2.3.4-beta.1with npm tagsnapshot. - for pax/zip(gradle) package, it will be published to
libs-release-local/org/zowe/<component>/2.3.4/as<component>-2.3.4-beta.1.(pax|zip).
- for npm package, it will be published to
- Github tag
v2.3.4-beta.1will be created. - No version bump will be performed on GitHub after release.
- Build on
- Scenario #3
- Build on
masterwith (Perform Release= true,Pre-Release String= empty)- for npm package, it will be published to
npm-local-releaseasv2.3.4with npm default taglatest. - for pax/zip(gradle) package, it will be published to
libs-release-local/org/zowe/<component>/2.3.4/as<component>-2.3.4.(pax|zip).
- for npm package, it will be published to
- Github tag
v2.3.4will be created. - A PATCH level version bump will be performed on GitHub. This is to avoid release the same version again. So after version bump,
masterhas version of2.4.0, and a commit can be seen from github commit history. This commit should be merged/cherry-picked back tostaging.
- Build on
- Scenario #dev-1
- Build on
stagingwhich IS a release branch with default parameter values (Perform Release= false,Pre-Release String= empty)- for npm package, it will be published to
npm-local-releaseasv2.3.4-staging-snapshot.20190101000000with npm tagsnapshot. - for pax/zip(gradle) package, it will be published to
libs-snapshot-local/org/zowe/<component>/2.3.4-staging/as<component>-2.3.4-staging.20190101000000.(pax|zip).
- for npm package, it will be published to
- No github tag will be created.
- No version bump will be performed on GitHub.
- Build on
- Scenario #dev-2
- Build on
stagingwhich IS a release branch with default parameter values (Perform Release= true,Pre-Release String= rc.1)- for npm package, it will be published to
npm-local-releaseasv2.3.4-rc.1with npm tagdev. - for pax/zip(gradle) package, it will be published to
libs-snapshot-local/org/zowe/<component>/2.3.4-staging/as<component>-2.3.4-staging.20190101000000.(pax|zip).
- for npm package, it will be published to
- No github tag will be created.
- No version bump will be performed on GitHub after release.
- Build on
- Scenario #dev-3
- Build on
stagingwhich IS a release branch with default parameter values (Perform Release= true,Pre-Release String= empty) - Build will be rejected because pre-release string is empty.
- Build on
- Typical Scenario
- A NPM project has
latest,dev,v1-latestandv1-devtags.v1is a LTS version, currentmasteris onv2.3.4. - There are 4 branches can do a release, the branch-tag mappings are:
master-lateststaging-devv1.x/master-v1-latestv1.x/staging-v1-dev
- A NPM project has
Release Scenarios
- Release v2.3.4-rc.1
- Build
stagingwith (Perform Release= true,Pre-Release String= rc.1). - Or build
masterwith (Perform Release= true,Pre-Release String= rc.1), not suggested.
- Build
- Release v2.3.4
- Build
masterwith (Perform Release= true,Pre-Release String= empty).
- Build
- Release v2.4.0
- Make a commit on
stagingto upgrade version to2.4.0. - Build
stagingwith (Perform Release= true,Pre-Release String= rc.1), we should havev2.4.0-rc.1. - Create a Pull Request to merge
stagingintomaster. After merged,mastershould have a version definition of2.4.0instead of2.3.4. - build master with (
Perform Release= true,Pre-Release String= empty), we should havev2.4.0.
- Make a commit on