Jenkinsfile pipeline with shell script

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!

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

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

Thanks for your feedback, and welcome to this community @luisthiago3108 :wave: .