Extends the functionality available in the Pipeline class. This class adds methods for building and testing your application.
A typical pipeline should include these stage in sequence:
@Library('fill this out according to your setup') import org.zowe.jenkins_shared_library.pipelines.generic.GenericPipeline node('pipeline-node') { GenericPipeline pipeline = new GenericPipeline(this) // Set your config up before calling setup pipeline.admins.add("userid1", "userid2", "userid3") // update branches settings if we have different settings from #defineDefaultBranches() pipeline.branches.addMap([ [ name : 'lts-incremental', isProtected : true, buildHistory : 20, ] ]) // MUST BE CALLED FIRST pipeline.setup( // Define the git configuration github: [ email: 'git-user-email@example.com', usernamePasswordCredential: 'git-user-credentials-id' ], // Define the artifactory configuration artifactory: [ url : 'https://your-artifactory-url', usernamePasswordCredential : 'artifactory-credential-id', ] ) pipeline.build() // Provide required parameters in your pipeline pipeline.test() // Provide required parameters in your pipeline pipeline.publish() // Provide required parameters in your pipeline pipeline.release() // Provide required parameters in your pipeline // MUST BE CALLED LAST pipeline.end() }
Modifiers | Name | Description |
---|---|---|
protected static java.lang.String |
BUILD_PARAMETER_PERFORM_RELEASE |
Build parameter name for "Perform Release" |
protected static java.lang.String |
BUILD_PARAMETER_PRE_RELEASE_STRING |
Build parameter name for "Pre-Release String" |
protected GenericPipelineControl |
_control |
More control variables for the pipeline. |
protected java.util.List<java.lang.String> |
_junitResults |
Holds junit test result files. |
protected java.lang.String |
_manifestFormat |
Format of manifest file. |
protected java.util.Map |
_manifestObject |
Object of manifest. |
protected static java.lang.String |
temporaryUploadSpecName |
Temporary upload spec name |
Fields inherited from class | Fields |
---|---|
class org.zowe.jenkins_shared_library.pipelines.base.Pipeline |
__$stMC |
Type | Name and description |
---|---|
org.zowe.jenkins_shared_library.artifact.JFrogArtifactory |
artifactory JFrogArtifactory instance |
java.lang.String |
artifactoryUploadTargetFile Artifactory file name pattern when the pipeline try to publish artifacts. |
java.lang.String |
artifactoryUploadTargetPath Artifactory upload path pattern when the pipeline try to publish artifacts. |
org.zowe.jenkins_shared_library.pipelines.base.Branches<org.zowe.jenkins_shared_library.pipelines.generic.models.GenericBranch> |
branches A map of branches. |
ChangeInformation |
changeInfo Stores the change information for reference later. |
org.zowe.jenkins_shared_library.scm.GitHub |
github GitHub instance |
java.lang.String |
githubTagPrefix Github tag prefix |
java.lang.String |
manifest Manifest file name/path |
java.util.Map |
packageInfo Package information extracted from project. |
org.zowe.jenkins_shared_library.package.Pax |
pax PAX packaging instance |
java.lang.String |
publishTargetVersion The full version pattern when the pipeline try to publish artifacts. |
Constructor and description |
---|
GenericPipeline
(java.lang.Object steps) Constructs the class. |
Type Params | Return Type | Name and description |
---|---|---|
|
protected java.lang.String |
_parseString(java.lang.String str, java.util.Map<java.lang.String, java.lang.String> macros) Parse a string using macros Map. |
|
protected void |
_readPackageManifest() Read manifest file if exists and fill in packageInfo. |
|
protected static void |
_validateReportInfo(TestReport report, java.lang.String reportName, java.lang.String stageName) Validates that a test report has the required options. |
|
protected void |
build(java.util.Map arguments = [:]) Pseudo build method, should be overridden by inherited classes |
|
void |
buildGeneric(BuildStageArguments arguments) Creates a stage that will build a generic package. |
|
void |
buildGeneric(java.util.Map arguments = [:]) Creates a stage that will build a generic package. |
|
protected void |
bumpVersion() This method should be overridden to properly bump version in different kind of project. |
|
protected void |
defineDefaultBranches() Setup default branch settings |
|
protected void |
end(java.util.Map arguments = [:]) Pseudo end method, should be overridden by inherited classes |
|
void |
endGeneric(java.util.Map arguments = [:]) Signal that no more stages will be added and begin pipeline execution. |
|
protected java.util.Map<java.lang.String, java.lang.String> |
extractArtifactoryUploadTargetFileMacros(java.lang.String file) Extract macro of "filename" and "fileext" for artifactory upload file. |
|
java.lang.String |
getBranchTag(java.lang.String branch = '') Get branch tag |
|
protected java.util.Map<java.lang.String, java.lang.String> |
getBuildStringMacros(java.util.Map<java.lang.String, java.lang.String> macros = [:]) Return map of build string macros. |
|
java.lang.String |
getPreReleaseString() The pre-release string parameter of current build. |
|
java.lang.String |
getPublishTargetPath(java.util.Map arguments = [:]) Get real publish target path |
|
java.lang.Boolean |
isFormalReleaseBranch(java.lang.String branch = '') If current pipeline branch can do a formal release |
|
java.lang.Boolean |
isPerformingRelease() If current build is a release build based on the build parameter which starts the build. |
|
java.lang.Boolean |
isReleaseBranch(java.lang.String branch = '') If current pipeline branch can do a release. |
|
protected void |
packaging(java.util.Map arguments) Pseudo packaging method, should be overridden by inherited classes |
|
void |
packagingGeneric(PackagingStageArguments arguments) Creates a stage that will package artifact(s). |
|
void |
packagingGeneric(java.util.Map arguments = [:]) Creates a stage that will package artifact(s). |
|
protected void |
publish(java.util.Map arguments) Pseudo publish method, should be overridden by inherited classes |
|
void |
publishGeneric(PublishStageArguments arguments) Creates a stage that will publish artifacts to Artifactory. |
|
void |
publishGeneric(java.util.Map arguments = [:]) Creates a stage that will publish artifacts to Artifactory. |
|
protected void |
release(java.util.Map arguments = [:]) Pseudo release method, should be overridden by inherited classes |
|
void |
releaseGeneric(java.util.Map arguments = [:]) Creates a stage that will execute a release |
|
void |
releaseGeneric(ReleaseStageArguments arguments) Creates a stage that will execute a release |
|
protected void |
sendReleaseNotice() Send out email notification for the new version released. |
|
protected void |
setup(java.util.Map arguments = [:]) Pseudo setup method, should be overridden by inherited classes |
|
void |
setupGeneric(GenericSetupStageArguments arguments) Calls Pipeline.setupBase to setup the build. |
|
void |
setupGeneric(java.util.Map arguments = [:]) Initialize the pipeline. |
|
protected void |
sonarScan(java.util.Map arguments = [:]) Pseudo SonarQube Scan method, should be overridden by inherited classes |
|
void |
sonarScanGeneric(SonarScanStageArguments arguments) Creates a stage that will perform SonarQube static code scanning. |
|
void |
sonarScanGeneric(java.util.Map arguments = [:]) Creates a stage that will execute SonarQube code scan on your application. |
|
protected void |
tagBranch(java.lang.String tagPrefix = '') Tag branch when release. |
|
protected void |
test(java.util.Map arguments = [:]) Pseudo test method, should be overridden by inherited classes |
|
void |
testGeneric(TestStageArguments arguments) Creates a stage that will execute tests on your application. |
|
void |
testGeneric(java.util.Map arguments = [:]) Creates a stage that will execute tests on your application. |
|
void |
uploadArtifacts(java.util.List<java.lang.String> artifacts, java.lang.String baseTargetPath = "") Upload artifacts. |
Methods inherited from class | Name |
---|---|
class org.zowe.jenkins_shared_library.pipelines.base.Pipeline |
org.zowe.jenkins_shared_library.pipelines.base.Pipeline#getSteps(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#setSteps(java.lang.Object), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#setupBase(org.zowe.jenkins_shared_library.pipelines.base.arguments.SetupStageArguments), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#setupBase(java.util.Map), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#setupBase(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#getBranches(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#setBranches(org.zowe.jenkins_shared_library.pipelines.base.Branches), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#createStage(java.util.Map), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#createStage(org.zowe.jenkins_shared_library.pipelines.base.arguments.StageArguments), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#addBuildParameter(java.lang.Object), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#addBuildOption(java.lang.Object), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#addBuildParameters([Lorg.jenkinsci.plugins.structs.describable.UninstantiatedDescribable;), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#addBuildParameters(java.util.List), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#addUpstreams([Ljava.lang.String;), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#getFirstFailingStage(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#getAdmins(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#getBuildOptions(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#setBuildOptions(java.util.List), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#getBuildParameters(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#setBuildParameters(java.util.List), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#getBuildUpstreams(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#setBuildUpstreams(java.util.List), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#setVersion(java.lang.String), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#endBase(org.zowe.jenkins_shared_library.pipelines.base.arguments.EndArguments), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#endBase(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#endBase(java.util.Map), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#getStage(java.lang.String), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#setPackageName(java.lang.String), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#setBaseDirectory(java.lang.String), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#getVersion(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#invokeMethod(java.lang.String, java.lang.Object), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#getMetaClass(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#setMetaClass(groovy.lang.MetaClass), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#setResult(org.zowe.jenkins_shared_library.pipelines.base.enums.ResultEnum), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#getBaseDirectory(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#setProperty(java.lang.String, java.lang.Object), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#getProperty(java.lang.String), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#getPackageName(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#wait(long, int), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#wait(long), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#wait(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#equals(java.lang.Object), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#toString(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#hashCode(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#getClass(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#notify(), org.zowe.jenkins_shared_library.pipelines.base.Pipeline#notifyAll() |
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Build parameter name for "Perform Release"
Build parameter name for "Pre-Release String"
More control variables for the pipeline.
Holds junit test result files.
This is internal used to avoid publishing duplicated junit file to Jenkins.
Format of manifest file.
The value could be json or yaml.
The value is calculated based on manifest file name.
Object of manifest.
The value is calculated based on manifest file content.
Temporary upload spec name
".tmp-pipeline-publish-spec.json"
JFrogArtifactory instance
Artifactory file name pattern when the pipeline try to publish artifacts.
"{filename}-{publishversion}{fileext}"
my-artifact.zip
, the pipeline
may interpret the targe file name as "my-artifact-1.2.3-snapshot-23-20190101010101.zip"
.Artifactory upload path pattern when the pipeline try to publish artifacts.
branchtag
is lower case characters."{repository}/{package}{subproject}/{version}{branchtag-uc}/"
"lib-snapshot-local/org/zowe/my-project/1.2.3-STAGINGS-TLS/"
.A map of branches.
Stores the change information for reference later.
GitHub instance
Github tag prefix
If you set a prefix example
, then all version tags like v1.2.3
will have a github tag example-v1.2.3
.
Manifest file name/path
Set to file path if the repository has Zowe manifest file. This is optional. By default, the Generic pipeline will try manifest.json, manifest.yaml or manifest.yml in root directory.
Package information extracted from project.
Based on type of project, the keys included could be vary.
PAX packaging instance
The full version pattern when the pipeline try to publish artifacts.
"{version}{prerelease}{branchtag}{buildnumber}{timestamp}"
"1.2.3-snapshot-23-20190101010101"
.Constructs the class.
When invoking from a Jenkins pipeline script, the GenericPipeline must be passed the current environment of the Jenkinsfile to have access to the steps.
def pipeline = new GenericPipeline(this)
steps
- The workflow steps object provided by the Jenkins pipelineParse a string using macros Map.
Macros wrap with curly brackets will be replace in the string. For example, all occurence
of {repository}
in the string will be replaced with value of macro key
repository
.
str
- string to parsemacros
- map of macros to replaceRead manifest file if exists and fill in packageInfo.
Validates that a test report has the required options.
report
- The report to validatereportName
- The name of the report being validatedstageName
- The name of the stage that is executing.Pseudo build method, should be overridden by inherited classes
arguments
- A map of arguments to be applied to the BuildStageArguments used to define
the stage.Creates a stage that will build a generic package.
Calling this function will add the following stage to your Jenkins pipeline. Arguments passed to this function will map to the BuildStageArguments class. The BuildStageArguments.operation will be executed after all checks are complete. This must be provided or a java.lang.NullPointerException will be encountered.
The following exceptions can be thrown by the build stage:
build
but had to be named
buildGeneric
due to the issues described in Pipeline.arguments
- A map of arguments to be applied to the BuildStageArguments used to define
the stage.Creates a stage that will build a generic package.
arguments
- A map that can be instantiated as org.zowe.jenkins_shared_library.pipelines.generic.arguments.BuildStageArgumentsThis method should be overridden to properly bump version in different kind of project.
For example, npm package should use `npm version patch` to bump, and gradle project should
update the version
definition in "gradle.properties"
.
Setup default branch settings
Pseudo end method, should be overridden by inherited classes
arguments
- A map that can be instantiated as EndArguments.Signal that no more stages will be added and begin pipeline execution.
arguments
- Arguments to send to Pipeline.endBaseExtract macro of "filename" and "fileext" for artifactory upload file.
filename
and fileext
extracted from the file path does not include
path to the file and version information.
For example, if we have a local artifact "./path/to/my-artifact-1.2.3-snapshot.zip"
, then
the expected macros extracted are: [filename: "my-artifact", fileext: "zip"]
file
- original file nameGet branch tag
branch
- the branch name to check. By default, empty string will check current branchReturn map of build string macros. Those macros will be used to parse build string.
macros
- default value of macros.The pre-release string parameter of current build.
Get real publish target path
publishTargetPath
- overwrite default publish path patternIf current pipeline branch can do a formal release
branch
- the branch name to check. By default, empty string will check current branchIf current build is a release build based on the build parameter which starts the build.
If current pipeline branch can do a release.
branch
- the branch name to check. By default, empty string will check current branchPseudo packaging method, should be overridden by inherited classes
arguments
- The arguments for the packaging step. arguments.name
must be
provided.Creates a stage that will package artifact(s).
The default behavior of this stage will check if there is a local PAX workspace presents. If so, then run a PAX packaging process to generate a Pax package.
Provide arguments.operation to override the default behavior.
Calling this function will add the following stage to your Jenkins pipeline. Arguments passed to this function will map to the PackagingStageArguments class. The PackagingStageArguments.operation will be executed after all checks are complete. This must be provided or a java.lang.NullPointerException will be encountered.
The following exceptions can be thrown by the sonar scan stage:
pacakging
but had to be named
packagingGeneric
due to the issues described in Pipeline.arguments
- A map of arguments to be applied to the SonarScanStageArguments used to define
the stage.Creates a stage that will package artifact(s).
arguments
- A map that can be instantiated as org.zowe.jenkins_shared_library.pipelines.generic.arguments.PackagingStageArgumentsPseudo publish method, should be overridden by inherited classes
arguments
- The arguments for the publish step.Creates a stage that will publish artifacts to Artifactory.
By default, if you publish a pre-release version on formal release branch, the pipeline will
show a confirmation information requiring human intervene. For example, you want to publish
rc1
on master
branch. Normally a pre-release should be released from staging
branch. Set PublishStageArguments.allowPublishPreReleaseFromFormalReleaseBranch
to true to disable it.
The stage will adhere to the following conditions:
The Publish stage will throw the following exceptions:
publish
but had to be named
publishGeneric
due to the issues described in Pipeline.arguments
- The arguments for the publish step.Creates a stage that will publish artifacts to Artifactory.
arguments
- A map that can be instantiated as org.zowe.jenkins_shared_library.pipelines.generic.arguments.PublishStageArgumentsPseudo release method, should be overridden by inherited classes
arguments
- The arguments for the release step.Creates a stage that will execute a release
Creates a stage that will execute a release
The default behavior of release stage is after the publish stage, which release artifacts have been uploaded to Artifactory, we have to tag the GitHub branch with the release. If this is a formal release, we also need to bump project version, so we won't build same version again. The version bump will create a commit and push to GitHub. After all, the stage will send out email notification for the new release.
Provide arguments.operation to override the default behavior. Or you can provide arguments.tagBranch or arguments.bumpVersion to override part of the behavior.
Calling this function will add the following stage to your Jenkins pipeline. Arguments passed to this function will map to the org.zowe.jenkins_shared_library.pipelines.generic.arguments.ReleaseStageArguments class. The org.zowe.jenkins_shared_library.pipelines.generic.arguments.ReleaseStageArguments#operation will be executed after all checks are complete. This must be provided or a java.lang.NullPointerException will be encountered.
This stage will adhere to the following conditions:
The following exceptions will be thrown if there is an error.
release
but had to be named
releaseGeneric
due to the issues described in Pipeline.arguments
- A map of arguments to be applied to the org.zowe.jenkins_shared_library.pipelines.generic.arguments.ReleaseStageArguments used to define the stage.Send out email notification for the new version released.
Pseudo setup method, should be overridden by inherited classes
arguments
- A map that can be instantiated as GenericSetupStageArgumentsCalls Pipeline.setupBase to setup the build.
#init()
methods of dependended instances,
for example, GitHub, JFrogArtifactory, Pax etc. This step is placed in a stage because
some initlialization requires code checkout. You can specify GenericSetupStageArguments.extraInit to extend the
default initialization.
setup
but had to be named
setupGeneric
due to the issues described in Pipeline.Initialize the pipeline.
arguments
- A map that can be instantiated as GenericSetupStageArgumentsPseudo SonarQube Scan method, should be overridden by inherited classes
arguments
- The arguments for the sonarScan step.Creates a stage that will perform SonarQube static code scanning.
The default behavior of this stage will check if there is a "sonar-project.properties"
file presents. If so, then run a SonarQube static code scanning using that configuration file.
Provide arguments.operation to override the default behavior.
Calling this function will add the following stage to your Jenkins pipeline. Arguments passed to this function will map to the SonarScanStageArguments class. The SonarScanStageArguments.operation will be executed after all checks are complete. This must be provided or a java.lang.NullPointerException will be encountered.
The following exceptions can be thrown by the sonar scan stage:
"sonar-project.properties"
file presents. This file should have
basic scanning configurations.sonarScan
but had to be named
sonarScanGeneric
due to the issues described in Pipeline.arguments
- A map of arguments to be applied to the SonarScanStageArguments used to define
the stage.Creates a stage that will execute SonarQube code scan on your application.
arguments
- A map that can be instantiated as org.zowe.jenkins_shared_library.pipelines.generic.arguments.SonarScanStageArgumentsTag branch when release.
"1.2.3"
with pre-release string "rc1"
, we will
creating a tag "v1.2.3-rc1"
.tagPrefix
- if prefix the tag with an identifierPseudo test method, should be overridden by inherited classes
arguments
- A map of arguments to be applied to the TestStageArguments used to define
the stage.Creates a stage that will execute tests on your application.
Arguments passed to this function will map to the TestStageArguments class.
Runs one of your application tests. If the test operation throws an error, that error is ignored and will be assumed to be caught in the junit processing. Some test functions may exit with a non-zero return code on a test failure but may still capture junit output. In this scenario, it is assumed that the junit report is either missing or contains failing tests. In the case that it is missing, the build will fail on this report and relevant exceptions are printed. If the junit report contains failing tests, the build will be marked as unstable and a report of failing tests can be viewed.
The following reports can be captured:
The test stage will execute by default if the current build result is greater than or equal to org.zowe.jenkins_shared_library.pipelines.base.enums.ResultEnum#UNSTABLE. If a different status is passed, that will take precedent.
After the test is complete, the stage will continue to collect the JUnit Report and the Test Results HTML Report. The stage will fail if either of those are missing. If specified, the Cobertura Report are then captured. The build will fail if these reports are to be collected and were missing.
The test stage can throw the following exceptions:
test
but had to be named
testGeneric
due to the issues described in Pipeline.arguments
- A map of arguments to be applied to the TestStageArguments used to define
the stage.Creates a stage that will execute tests on your application.
arguments
- A map that can be instantiated as org.zowe.jenkins_shared_library.pipelines.generic.arguments.TestStageArgumentsUpload artifacts.
This is a part of publish stage default behavior. If org.zowe.jenkins_shared_library.pipelines.generic.arguments.PublishStageArguments#artifacts is defined, those artifacts will be uploaded to artifactory with this method.
artifacts
- list of artifacts. glob file pattern is allowed.baseTargetPath
- The targe path to uploadGroovy Documentation