We use similar conditionals ... and I think your error is in the branch 
name:

env.BRANCH_NAME == 'origin/master'

that should be instead:

env.BRANCH_NAME == 'master'

Because, if I'm guessing right, you are using Git ... and then the first 
part is the remote name, not the branch: <remote_name>/<branch_name> :-) 

So, in your case the BRANCH_NAME is "master" and "origin" is the remote ... 
that you don't have to specify in Jenkins pipeline.


On Tuesday, 31 March 2020 14:44:06 UTC+1, kurusetra wrote:
>
> Hi,
>
> I just created jenkinsfile for deploy sample application to my k8s, but 
> the deployment always build "dev" image and deploy to dev namespace in k8s. 
> i tried to commit in master branch but still build "dev" image dan deploy 
> to "dev" namespace in k8s.
>
> Please advice... whats wrong with my pipeline, fyi... i create the job in 
> jenkins with "freestyle".
>
> pipeline {
>>     agent any
>>     environment {
>>         project_id = 'kurusetra'
>>         app_name = 'nginx-hello'
>>     }
>>
>>     stages {
>>
>>         stage('Clone Repository') {
>>             steps {
>>                 checkout scm
>>             }
>>         }
>>
>>         stage('Build Docker Images') {
>>             steps {
>>                 script {
>>                     if (env.BRANCH_NAME == 'origin/master') {
>>                         myapp = 
>> docker.build("${project_id}/${app_name}-prod:${env.BUILD_NUMBER}")
>>                     } else {
>>                         myapp = 
>> docker.build("${project_id}/${app_name}-dev:${env.BUILD_NUMBER}")
>>                     }
>>                 }
>>             }
>>         }
>>
>>         stage('Push Images') {
>>             steps {
>>                 script {
>>                     docker.withRegistry('https://docker.xxx.com/kurusetra', 
>> 'harbor') {
>>                         myapp.push("${env.BUILD_NUMBER}")
>>                         myapp.push("latest")
>>                     }
>>                 }
>>             }
>>         }
>>
>>         stage('Deploy to K8s') {
>>             steps {
>>                 script {
>>                     if (env.BRANCH_NAME == 'origin/master') {
>>                         sh "sed -i 
>> 's/${app_name}:latest/${app_name}-prod:${env.BUILD_NUMBER}/g' 
>> deployment.yaml"
>>                         sh 'kubectl apply -f ./deployment.yaml -n prod'
>>                     } else {
>>                         sh "sed -i 
>> 's/${app_name}:latest/${app_name}-dev:${env.BUILD_NUMBER}/g' 
>> deployment.yaml"
>>                         sh 'kubectl apply -f ./deployment.yaml -n dev'
>>                     }
>>                 }
>>             }
>>         }
>>     }
>> }
>>
>
>
> Thanks
> Kurusetra 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/297a604e-aed8-423b-86c4-89b0baca6fac%40googlegroups.com.

Reply via email to