Jenkinsfile pipeline with script shell
I have three branches on Gitlab (int, stg and prd), I need running a pipeline to do deploy when accepted a merge. Example: int → stg, stg → prd. Whats better way to do this? The code need getting which branch was merged to build the deploy on the branch correct.
Help me, please!
halkeye
(Gavin Mogan)
October 6, 2022, 4:43pm
2
when { branch { "stg" } }
steps {
sh("deploy to stg")
}
@halkeye thanks for answering
I tried yesterday a code similar. Follow below
agent any
stages {
stage(‘Build For Int’) {
when { branch ‘integration’ }
steps {
script {
echo “Estamos na integration”
}
}
stage(‘Build For Prod’) {
when { branch ‘master’ }
steps {
script {
echo “Estamos na production”
Today I tried your suggest, returned error below
halkeye
(Gavin Mogan)
October 6, 2022, 5:47pm
4
my bad, i did it from memory instead of looking it up
when { branch "integration" }
1 Like
Solved with these parameters!
stage ('Running script CI') {
steps {
script {
if(gitlabTargetBranch.equals('int)){
sh 'running script int'
} else if(gitlabTargetBranch.equals('stg')){
sh 'running script stg'
} else if(gitlabTargetBranch.equals('prd')){
sh 'running script prd'
}
}
}
1 Like
poddingue
(Bruno Verachten)
October 17, 2022, 7:33am
6
Thanks for your feedback, and welcome to this community @luisthiago3108 .