Jenkins Pipeline Plugin - how to inject global passwords?

7,074 views
Skip to first unread message

Ant Weiss

unread,
Apr 24, 2016, 8:24:39 AM4/24/16
to Jenkins Users
For regular jobs if I don't want to make passwords publicly visible I use EnvInject plugin with either global or job passwords.
This masks the passwords in log output and make them available as env variables.
What is the right way to do this when wrting pipeline DSL scripts?

Thanks a lot!!!

Daniel Beck

unread,
Apr 24, 2016, 10:33:22 AM4/24/16
to jenkins...@googlegroups.com

> On 24.04.2016, at 14:24, Ant Weiss <ant....@gmail.com> wrote:
>
> What is the right way to do this when wrting pipeline DSL scripts?
>

Credentials and Credentials Binding Plugin:

https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Binding+Plugin

Harry G.

unread,
Apr 25, 2016, 5:55:14 AM4/25/16
to Jenkins Users, m...@beckweb.net
Please note: Credentials Binding works, but currently it is not possible to mask passwords in the log with this solution.
https://issues.jenkins-ci.org/browse/JENKINS-24805
A PR from Cloudbees is in work, but not finished
https://groups.google.com/forum/#!msg/jenkinsci-users/GgX3RSckVlI/LU8IqzqoMwAJ

Until this is done, the only way to mask passwords in the log is EnvInject or MaskPassword Plugin (with their respective backdraws).
You could possibly externalize parts of your pipeline to a freestyle job and use them.

Official doc suggests to turn off log (set +x), if you can do this reliably for all relevant jobs:
https://cloudbees.zendesk.com/hc/en-us/articles/203802500-Injecting-Secrets-into-Jenkins-Build-Jobs
If you have several people working on build jobs/scripts I would discourage from doing this.

Ant Weiss

unread,
Apr 25, 2016, 7:54:14 AM4/25/16
to Jenkins Users, m...@beckweb.net
Hi all,
thanks for your inputs.
In fact I implemented this with Credentials Binding plugin and it worked great - masking the passwords as it should.

Brian Ray

unread,
Apr 26, 2016, 5:17:56 PM4/26/16
to Jenkins Users, m...@beckweb.net
I recently started experimenting with Credentials Binding with a Pipeline script passing a user-password credential down to a sh/bat step inside a node block, with the secret values masked perfectly in the log. (The step just executed some Groovy that println System.getenv()'d the protected env variable.) In fact the masking worked so well I had to add some equality tests against the value to ensure that the secret value was indeed the right value.

Maybe my use case was different than JENKINS-24805.

Harry G.

unread,
Apr 27, 2016, 5:28:17 AM4/27/16
to Jenkins Users
Wow, this is strange!
To be honest, my test case was a freestyle job and I assumed there should be no difference.
I tried again and it really works in pipeline, but not in freestyle job - with exact same credential binding and same shell script!

So I think this can help to fix JENKINS-24805
So thanks a lot for bringing this up and sorry for the confusion!

Brian Ray

unread,
Apr 27, 2016, 11:51:35 AM4/27/16
to Jenkins Users
Glad to help. Very good to know the differing behavior between freestyle and pipeline jobs.

Brian Ray

unread,
May 13, 2016, 12:20:17 PM5/13/16
to Jenkins Users
Found a wrinkle to masking secrets in the log, in one of my edge cases Pipeline.

I'm trying to determine whether this edge case warrants a JIRA.

kumar naresh

unread,
Apr 3, 2017, 7:45:08 AM4/3/17
to Jenkins Users, m...@beckweb.net

Hi,

please help to get the global passwords list from jenkins using the groovy scripting.

Regards,
kumar.
Reply all
Reply to author
Forward
0 new messages