-
Notifications
You must be signed in to change notification settings - Fork 146
standalone deployment pipeline for Jenkins #376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thadbeeraf
wants to merge
15
commits into
IBM:main
Choose a base branch
from
thadbeeraf:feature/CTTM-1508
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4cfe856
Gitlab cd pipeline
391587d
Merge branch 'IBM:main' into main
thadbeeraf 1e4cf8e
cleanup
eb31867
standalone deployment pipeline for Jenkins
66d806e
Update README.md
thadbeeraf 7dc4cfe
Apply suggestions from code review
thadbeeraf a600d2f
cleanup
6b39572
cleanup
fb62a5e
revert the changes
db6d0b0
cleanup
12456c1
corrected jenkinsfile
2387082
cleanup
5db8f5d
cleanup
0ced6de
Update Templates/Deploy_Pipeline/Jenkins/README.md
thadbeeraf 3b8007e
PR changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| def JenkinsAgent = "ztec-201-STC" | ||
| def pipeverbose = true | ||
|
|
||
| pipeline { | ||
| agent { label JenkinsAgent } | ||
|
|
||
| environment { | ||
| GIT_STRATEGY = "none" | ||
| GIT_CHECKOUT = "false" | ||
| wdEnvironmentFile = "EOLEB7-${application}-${targetEnvironment.capitalize()}.yaml" //Make sure the referenced file matches the required naming convention | ||
| wdEvidencePath = "deploy/evidences" | ||
| wdEvidencesRoot = "/var/work/wazi_deploy_evidences_jenkins/" | ||
| wdEvidencesIndex = "/var/work/wazi_deploy_evidences_jenkins_index/" | ||
| uniqueWorkspaceId = "${WORKSPACE}/${application}/deploy-${buildId}" | ||
| deployOutputDirectory = "${WORKSPACE}/${application}/DEPLOY-OUTPUT" | ||
| } | ||
|
|
||
| parameters { | ||
| string(name: 'application', defaultValue: '', description: 'Application name (e.g., retirementCalculator, MortgageApplication)') | ||
| choice(name: 'PackageType', choices: ['build', 'release'], description: 'Package type: a preliminary build or release candidate') | ||
| string(name: 'buildId', defaultValue: '', description: 'Build pipeline ID (e.g., 00000018)') | ||
| string(name: 'packageReference', defaultValue: '', description: 'Release version( release pipeline, eg:release eg: rel-1.6.1 ) or branch name( for build pipeline, eg: main, feature) ') | ||
| choice(name: 'targetEnvironment', choices: ['integration', 'acceptance', 'production'], description: 'Deployment target environment') | ||
|
|
||
| } | ||
|
|
||
| options { | ||
| disableConcurrentBuilds() | ||
| timestamps() | ||
| } | ||
|
|
||
| stages { | ||
| stage('Validate Parameters') { | ||
| steps { | ||
| script { | ||
| echo "===============================" | ||
| echo "Deployment Pipeline Parameters" | ||
| echo "===============================" | ||
| echo "[INFO] Application: ${application}" | ||
| echo "[INFO] Package Type: ${PackageType}" | ||
| echo "[INFO] Build ID: ${buildId}" | ||
| echo "[INFO] Release Version: ${packageReference}" | ||
| echo "[INFO] Target Environment: ${targetEnvironment}" | ||
| echo "[INFO] Workspace: ${uniqueWorkspaceId}" | ||
| echo "===============================" | ||
|
|
||
| def errors = [] | ||
| if (!application) errors << "application is required" | ||
| if (!buildId) errors << "buildId is required" | ||
| if (errors) { | ||
| errors.each { echo "[ERROR] ${it}" } | ||
| error("[ERROR] Validation failed. Please fix input errors.") | ||
| } | ||
| echo "[SUCCESS] All validations passed" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| stage('Generate Plan') { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @thadbeeraf - The stages need a Today, they just continue to execute. |
||
| steps { | ||
| script { | ||
|
|
||
| echo "[INFO] Generating deployment plan for ${targetEnvironment}" | ||
| echo "[INFO] Package type: ${PackageType}" | ||
|
|
||
| def CMD = "" | ||
|
|
||
| CMD = "wazideploy-generate.sh -w ${uniqueWorkspaceId} -a ${application} -P ${packageType} -R ${packageReference} -I ${buildId}" | ||
|
|
||
| echo "[INFO] Executing command: ${CMD}" | ||
|
|
||
| def rc = sh(script: CMD, returnStatus: true) | ||
|
|
||
| if (rc == 0) { | ||
| echo "[INFO]: Plan generation passed (RC=0)" | ||
| } else { | ||
| echo "[ERROR]: Plan generation failed (RC=${rc})" | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| stage('Deploy') { | ||
| steps { | ||
| script { | ||
| echo "[INFO] Deploying to ${targetEnvironment} environment" | ||
| echo "[INFO] Using environment file: ${wdEnvironmentFile}" | ||
| echo "[INFO] Evidence path: ${wdEvidencePath}" | ||
| def CMD = "" | ||
| CMD = "wazideploy-deploy.sh -w ${uniqueWorkspaceId} -e ${wdEnvironmentFile} -l ${wdEvidencePath}/evidence.yaml < /dev/null" | ||
| echo "[INFO] Executing command: ${CMD}" | ||
|
|
||
| def rc = sh(script: CMD, returnStatus: true) | ||
|
|
||
| if (rc == 0) { | ||
| echo "[INFO]: Deployment passed. (RC=0)" | ||
| } else { | ||
| echo "[ERROR]: Deployment failed. (RC=${rc})" | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| stage('Report') { | ||
| steps { | ||
| script { | ||
|
|
||
| def reportDir = "${deployOutputDirectory}/deploy-${targetEnvironment}" | ||
| def sourceEvidenceFile = "${uniqueWorkspaceId}/deployPkgDir/deploy/evidences/evidence.yaml" | ||
| def wdEvidencesDir = "${wdEvidencesRoot}/${application}/${targetEnvironment}" | ||
| def wdEvidencesIndex = "${wdEvidencesIndex}" | ||
|
|
||
| echo "[INFO] Generating deployment report for ${targetEnvironment}" | ||
| def evidenceCmd = "" | ||
| evidenceCmd = "wazideploy-evidence.sh -w ${uniqueWorkspaceId} -l ${wdEvidencePath}/evidence.yaml -o deploy/deployment-report.html" | ||
| echo "[INFO] Executing command: ${evidenceCmd}" | ||
| sh evidenceCmd | ||
|
|
||
| sh "mkdir -p ${deployOutputDirectory}" | ||
| sh "mkdir -p ${reportDir}" | ||
| echo "[INFO] Using report directory: ${reportDir}" | ||
|
|
||
| // Persist evidence | ||
| sh "mkdir -p ${wdEvidencesDir} && mkdir -p ${wdEvidencesIndex}" | ||
| sh "cp ${sourceEvidenceFile} ${wdEvidencesDir}/evidence-${buildId}.yaml" | ||
| echo "[INFO] Persisted evidence file at ${wdEvidencesDir}" | ||
|
|
||
| // Update Wazi Deploy index | ||
|
|
||
| def indexCmd = "" | ||
|
|
||
| indexCmd = "wazideploy-evidence --index ${wdEvidencesIndex} --dataFolder ${wdEvidencesRoot} i" | ||
|
|
||
| echo "[INFO] Executing command: ${indexCmd}" | ||
|
|
||
| def rc = sh(script: indexCmd, returnStatus: true) | ||
|
|
||
| if (rc == 0) { | ||
| echo "[INFO]: Deployment report generated. (RC=0)" | ||
| } else { | ||
| echo "[ERROR]: Deployment report generation failed. (RC=${rc})" | ||
| } | ||
| sourceEvidenceFilePath = "${uniqueWorkspaceId}/deployPkgDir/deploy/evidences" | ||
|
|
||
| } | ||
| } | ||
| post { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| always { | ||
| // Pick up files created by the deployment. | ||
| dir ("${sourceEvidenceFilePath}") { | ||
| archiveArtifacts allowEmptyArchive: true, | ||
| artifacts: '*.yml,*.yaml', | ||
| excludes: '*clist', | ||
| onlyIfSuccessful: false | ||
| } | ||
| dir ("${WORKSPACE}/deployPkgDir/deploy") { | ||
| archiveArtifacts allowEmptyArchive: true, | ||
| artifacts: '*.html', | ||
| excludes: '*clist', | ||
| onlyIfSuccessful: false | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| stage ('Workspace Cleanup') { | ||
| steps { | ||
| script { | ||
| if (pipeverbose) { | ||
| println("[DEBUG]: Final Cleanup before deletes.") | ||
|
|
||
| dir("${WORKSPACE}") { | ||
| sh "pwd ; ls -al" | ||
| } | ||
| } | ||
|
|
||
| if (pipeverbose) { | ||
| println("[DEBUG]: Final Cleanup after deletes.") | ||
|
|
||
| dir("${WORKSPACE}") { | ||
| sh "pwd ; ls -al" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| post { | ||
| // Clean after build | ||
| always { | ||
| cleanWs(cleanWhenNotBuilt: false, | ||
| deleteDirs: true, | ||
| disableDeferredWipeout: true, | ||
| notFailBuild: true) | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| # Jenkins Deployment Pipeline Template | ||
|
|
||
| This template provides a [Jenkinsfile](Jenkinsfile) to set up a **Deployment pipeline** for applications managed in a Git repository. | ||
|
|
||
| ## Overview and Capabilities | ||
|
|
||
| This Jenkins pipeline implements the [Git-based process and branching model for mainframe development](https://ibm.github.io/z-devops-acceleration-program/docs/branching/git-branching-model-for-mainframe-dev) and leverages [Common Backend Scripts](https://github.com/IBM/dbb/blob/main/Templates/Common-Backend-Scripts/README.md) along with **IBM Wazi Deploy** to automate deployments of pre-built application packages from an artifact repository into integration, acceptance, and production environments on z/OS. | ||
|
|
||
| The pipeline supports **manual triggers** and implements the following stages: | ||
|
|
||
| * **Validate Parameters** | ||
| - Validates pipeline input parameters passed during manual trigger or via API. | ||
| - Determines the appropriate environment configuration file based on the selected target environment. | ||
| - Ensures required parameters (e.g., `application`, `buildId`, `PackageType`) are defined. | ||
thadbeeraf marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| * **Generate Plan** | ||
| - Uses [`wazideploy-generate.sh`](../../Common-Backend-Scripts/wazideploy-generate.sh) to create the deployment plan in z/OS Unix System Services (USS). | ||
| - Supports both the deployment of preliminary **build** and **release** packages. | ||
|
|
||
| * **Deploy** | ||
| - Executes [`wazideploy-deploy.sh`](../../Common-Backend-Scripts/wazideploy-deploy.sh) to deploy the application to the selected target environment. | ||
| - Produces initial evidence files and deployment logs. | ||
| - Uses `returnStatus` for robust error handling (`sh(script: ..., returnStatus: true)`). | ||
|
|
||
| * **Report** | ||
| - Invokes [`wazideploy-evidence.sh`](../../Common-Backend-Scripts/wazideploy-evidence.sh) to generate deployment reports and evidence summaries. | ||
| - Persists evidence files to centralized directories. | ||
| - Updates the Wazi Deploy evidence index for traceability. | ||
|
|
||
| * **Workspace Cleanup** | ||
| - Cleans up intermediate files and temporary deployment directories | ||
| --- | ||
|
|
||
| The pipeline supports controlled deployments to **integration**, **acceptance**, or **production** environments. | ||
| It uses Jenkins **stages**, **steps**, and **post conditions** for robust execution and error handling. | ||
|
|
||
|  | ||
|
|
||
| --- | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| To leverage this Jenkinsfile: | ||
|
|
||
| * A **Jenkins environment** with agents capable of running shell scripts and connecting to the z/OS UNIX System Services (USS) environment. | ||
| * Access to **IBM Wazi Deploy** scripts and **Common Backend Scripts** installed on the deployment agent. | ||
| * Appropriate workspace permissions for reading/writing deployment directories and evidence files. | ||
|
|
||
| --- | ||
|
|
||
| ## Installation and Setup | ||
|
|
||
| * Place the [Jenkinsfile](Jenkinsfile) in the root directory of your project repository. | ||
| * Please review the definitions thoroughly with your Jenkins administrator and adjust pipeline environment variables, workspace paths, and script locations according to your environment. | ||
|
|
||
| ### Required Parameters | ||
|
|
||
| | Parameter | Description | | ||
| | ------------------- | ----------------------------------------------------------------------------------- | | ||
| | `application` | Application name to deploy. | | ||
| | `buildId` | Build pipeline ID corresponding to the artifact. | | ||
| | `packageReference` | Release version (e.g., `rel-2.6.0`) or branch name(e.g., `main`, `feature`). | | ||
| | `targetEnvironment` | Deployment target (`integration`, `acceptance`, `production`). | | ||
| | `PackageType` | Package type: `build` or `release`. | | ||
|
|
||
| --- | ||
|
|
||
| ## Pipeline Usage | ||
|
|
||
| This Jenkinsfile can be executed: | ||
|
|
||
| * **Manually** via Jenkins → Build with Parameters | ||
|
|
||
| ### Example | ||
|
|
||
| 1. Open Jenkins → select the job → **Build with Parameters** | ||
| 2. Enter values: | ||
| Eg: | ||
| ``` | ||
| application: retirementCalculator | ||
| buildId: 12247 | ||
| packageReference: rel-1.6.1 | ||
| targetEnvironment: integration | ||
| PackageType: release | ||
|
|
||
| ``` | ||
|
|
||
| 3. Click **Build** | ||
|
|
||
| The pipeline will: | ||
|
|
||
| 1. Validate input parameters | ||
| 2. Generate a deployment plan | ||
| 3. Deploy the application | ||
| 4. Generate deployment report and evidence | ||
| 5. Clean up workspace | ||
|
|
||
| --- | ||
|
|
||
| ## Error Handling and Return Codes | ||
|
|
||
| * Shell commands are executed with `returnStatus: true` to capture **exit codes** without failing the pipeline immediately. | ||
| * Custom logic handles deployment errors, evidence generation failures, and workspace cleanup issues. | ||
| * Jenkins `post` blocks ensure **always-run cleanup** and artifact archiving. | ||
|
|
||
| --- | ||
|
|
||
|
|
||
| ## Summary | ||
|
|
||
| This Jenkinsfile provides a **robust deployment CD pipeline** for mainframe applications: | ||
|
|
||
| * Automates deployments of prebuilt packages to multiple environments | ||
| * Maintains auditable deployment evidence and reports | ||
| * Provides detailed logging and error handling | ||
| * Cleans workspace to maintain agent hygiene | ||
|
|
||
| It integrates **Common Backend Scripts** into enterprise Jenkins pipelines for automated, traceable deployment workflows. | ||
|
|
||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| This folder contains templates for standalone deployment pipelines. | ||
|
|
||
| Refer to [Deploy_Pipeline/REDME.md](../Deploy_Pipeline/README.md) | ||
| Documentation: | ||
|
|
||
| - [Gitlab Pipeline Templates](./Gitlab/README.md) | ||
| - [Jenkins Pipeline Overview](./Jenkins/README.md) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a previous version the description of the input parms were more details. Can we please add that back in?