mardi 12 février 2019

Jenkins Pipeline if-else script not giving expect result

I've been coming here for years and usually find the answer i seek but this time I have a rather specific question.

I am building a pipeline that runs through a set of steps in one pipeline with a 3 tier path path to prod, using a choice, couple of string, and withCredentials param. Which work fine, up until my prod deploy where it's failing an "if else" test.

I have a (secret text) jenkins credential with a basic password, that I am attempting to compare to the string entered on build start. I have checked the spell with basic usage and it works as expected. BUT when I add it to my full pipeline it fails.

I am thinking it is on account of my not using the correct syntax with steps, script, node, or order...? This is a new space for me and I'm hoping that someone who's spent more time in this code space will see my error. Thanks! In advance!

Fails:

...
      stage('Deploy_PROD') {
          when {
            expression { params.DEPLOY_TO == 'Deploy_PROD'}
          }
          steps{
                withCredentials([string(credentialsId: '${creds}', variable: 'SECRET')]) {
                script {
                    if  ('${password}' == '$SECRET') {
                        sh 'echo yes'
                    }  else {
                        sh 'echo no'
                }
            }
        }
      }
    }

Works:

stage('example')
        node {
            withCredentials([string(credentialsId: '${creds}', variable: 'SECRET')]) {
                if  ('${password}' == '$SECRET') { 
                    sh 'echo "test"'
                }  else {
                    sh 'echo ${password}'
                }
            }
        }

Aucun commentaire:

Enregistrer un commentaire