Day 78: Jenkins Conditional Pipeline
I have executed the Jenkins pipeline script. the script works fine when I tested from jenkins UI.
for both conditions master and feature, it runs as expected.
But it fails during the lab validation when condition is featuring branch, I observed that there is a change happening in the repository where feature file is getting replaced by a validation file , and the lab fails with error “feature file not found on the app server” , cause the file is getting deleted during the validation … this is the script
pipeline {
agent { label ‘stapp01’ }
stages {
stage('Deploy') {
steps {
script {
if (params.BRANCH == 'master') {
echo "Deploying master branch..."
checkout([$class: 'GitSCM',
branches: [[name: '*/master']],
userRemoteConfigs: [[url: 'http://gitea:3000/sarah/web_app.git']]
])
} else if (params.BRANCH == 'feature') {
echo "Deploying feature branch..."
checkout([$class: 'GitSCM',
branches: [[name: '*/feature']],
userRemoteConfigs: [[url: 'http://gitea:3000/sarah/web_app.git']]
])
} else {
error "Unsupported branch: ${params.BRANCH}. Use 'master' or 'feature'."
}
// Copy code into Apache document root
sh '''
sudo rm -rf /var/www/html/*
sudo cp -r * /var/www/html/
curl -s http://localhost:8080
'''
}
}
}
}
}