0

I'm a nubie to jenkins dsl. I'm trying to set credentials as an environment variable in order to use it in my fabfile . I first determine the credentials I want to use in a step context, than bind it in a wrapper block. The problem I so was that the wrapper block is executed before the steps block, thus creating an error of credentials not found. I'm not sure how I can set the values in a different way. any ideas? Added my code:

steps{
    shell('if [ "$my-variable" == "new" ]; then\n\
cred="new"\n\
echo "set cred to new" \n\
else\n\
cred="old"\n\
echo "set cred to old"\n\
fi;')
}

wrappers{
    credentialsBinding{
        usernamePassword('userVar', 'passwordVar', '${cred}')
    }
}

steps {
    shell(fab ${envName} start')
}
user2512231
  • 352
  • 2
  • 6
  • 17

1 Answers1

0

There are two problems in your script.

1) The build wrappers run before any build steps. The DSL allows to define steps and wrappers in any order, but the job will always run the wrappers before the steps.

2) Any shell variables you set are only visible within the shell step. Shell variables are not exposed to Jenkins.

I think this can be solved without using the first shell step, but I'm not sure what you are trying to achieve with that shell step. Maybe you should open a new question and describe the high-level problem that you are trying to solve.

daspilker
  • 8,154
  • 1
  • 35
  • 49