I have a declarative pipeline that uses some shared library I created to perform some commands requiring authentication. To perform these tasks, I can do it directly from my Jenkinsfile using the normal credentials syntax:
However, I can’t seem to get them passed into my shared library safely (i.e. avoiding Groovy double-quote expansion). The problem seems to be passing them in as arguments.
single quotes are not evaluated, so bash is trying to evaluate an environmental variable called $params. why not pass in the credential id, and use withCredentials {} block to create env variables with that credential just for that scope?
You’re right! It does seem that once we enter the shared library, withCredentials() works, even though the rest of the pipeline is declarative. This was confusing for me because, in the Declarative pipeline file, you cannot use the scripted Groovy shared library calls (e.g. I can’t do a “myclass.function()”, I just have to call “myclass()” and implement the call() function). So, while I am limited in how I can call shared libraries, once inside that call() function, apparently all scripting goes
Thanks for the support, and hopefully this helps someone else coming across this issue.