How to declare environments variables securely in JenkinsFile?


I’m beginner with Jenkins and I must build a Jenkins Pipeline for a project. I decided to use GitHub as SCM to manage project code and Jenkinsfiles. GitHub launch Jenkins pipeline thanks to webhook on each push.

The Jenkins pipeline is a multi-branch pipeline. So I can have one Jenkinsfile on each GitHub branch.

I must manage some credentials and other important variables during the pipeline. My query is the mean of use this type of variable without versionned them in the Jenkinsfiles which is versioned on GitHub.

How can I secure my variables during the workflow ? My jenkinsfile is versioned on Github. If I use the “env” step in JenkinsFile, all my variables will be visible and I don’t want that. GitHub doesn’t allow to manage environment variable if I didn’t use GitHub Action.

Thank you for your help.

You want to use the credentials system.

Then your jenkins file will just have the Id and not the actual credential. Plus it’ll mask the secrets in your console log