BAEL-5704:- Skip a stage in a Jenkins Pipeline (#13707)

This commit is contained in:
Kapil Khandelwal 2023-03-25 21:44:46 +05:30 committed by GitHub
parent 50d78ab618
commit 211e5fbbe2
3 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,32 @@
pipeline {
agent any
parameters {
booleanParam(name: 'skip_test', defaultValue: false, description: 'Set to true to skip the test stage')
}
stages {
stage('Build') {
steps {
sh 'echo "Building the application"'
}
}
stage('Test') {
steps {
execute_stage('Test', params.skip_test)
}
}
stage('Deploy') {
steps {
sh 'echo "Deploying the application"'
}
}
}
}
def execute_stage(stage_name, skip) {
stage(stage_name) {
if(skip) {
echo "Skipping ${stage_name} stage"
return
}
// Add steps to test the application
}

View File

@ -0,0 +1,29 @@
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'echo "Building the application"'
// Add steps to build the application
}
}
stage('Test') {
steps {
input message: 'Do you want to skip the test stage?', ok: 'Yes', parameters: [booleanParam(name: 'skip_test', defaultValue: false)], timeout: time(minutes: 5))
script {
if(params.skip_test) {
sh 'echo "Testing the application"'
return
}
}
// Add steps to test the application
}
}
stage('Deploy') {
steps {
sh 'echo "Deploying the application"'
// Add steps to deploy the application
}
}
}
}

View File

@ -0,0 +1,27 @@
pipeline {
agent any
parameters {
booleanParam(name: 'skip_test', defaultValue: false, description: 'Set to true to skip the test stage')
}
stages {
stage('Build') {
steps {
sh 'echo "Building application"'
// Add build steps here
}
}
stage('Test') {
when { expression { params.skip_test != true } }
steps {
sh 'echo "Testing application"'
// Add test steps here
}
}
stage('Deploy') {
steps {
sh 'echo "Deploying application"'
// Add deployment steps here
}
}
}
}