Hi,

Already changed from 'origin/master' to 'master' but still no luck, 
pipeline still build the 'dev' image dan deploy to namespace 'dev', even i 
commit in 'master' branch...
Yes i'm using github.com for codes repository...

Thanks
Kurusetra

On Tuesday, March 31, 2020 at 9:00:40 PM UTC+7, Gianluca wrote:
>
> 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/2d2e6bd2-8c66-4985-98fa-df8a560040e1%40googlegroups.com.

Reply via email to