We're using Jenkins to test our software on both Windows and Linux. Our Jenkins server (which doesn't have any data drives mounted) starts a Jenkins slave Job on one of our Windows machine which then needs to get data from a network drive that needs to be mounted with different user credentials.

So, I need something like

net use \\server\share /u:username PASSWORD
copy data

The problem is I don't want to write PASSWORD in my Jenkins execution script.

On Linux, we use an SSH keyfile and scp for that, but what's the equivalent for that on Windows?

  • You can use OpenSSH and WINSCP, just keep i mind that if you use WINSCP you will have to use keys with no PASSPHRASE, or else you would have to enter the passphrase everytime you run the script.
    – arana
    Commented Mar 18, 2016 at 16:35
  • Thanks for your efforts. I would need to figure out if our IT department is willing to install that on the machines though... From your answer I assume there are no native Windows commands / tools to do that?
    – fpnick
    Commented Mar 21, 2016 at 15:57
  • well not native no, but there are other alternatives to installing that, : you could: ' Compile' the batch file, so you dont have plain text pwd autoitscript.com/autoit3/docs/intro/compiler.htm but if someone is into it they could decompile or sniff from memory(no problem if this is just for regular users) or use RunAs /savecred (internal cmd) and save your credentials and ask for them if other uses runs the batch howtogeek.com/124087/…
    – arana
    Commented Mar 22, 2016 at 16:57

1 Answer 1


You can use Jenkins' built-in "Credentials" store just for that. Just create a new "Credentials" object (type: Username and password) and then -

If it's a pipeline job:

withCredentials([usernamePassword(credentialsId: 'MyCredentialsObjectId', passwordVariable: 'CREDS_P', usernameVariable: 'CREDS_U')]) {
    bat """
        net use \\server\share /u:%CREDS_U% %CREDS_P%
        REM copy data...

If it's a freestyle job, configure credential object to be used in "build environment" section - then use a batch step in the same manner.

Credentials will be maintained securely inside Jenkins, and will never appear in code. Additionally, Jenkins will make sure credentials are not leaked to console output, by replacing usernames and passwords with asterisks (***).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .