Cristian M
Cristian M

Reputation: 357

Is there a way to pass Jenkins credentials to automation test execution command?

I have created some global credentials in Jenkins, and I want to pass them to a powershell command that starts the execution of a protractor test suite. The credentials are created properly, the bindings are also done as you can see int he image below:

enter image description here

The thing is, I need these credentials to use them when running the automation tests. The powershell command that I execute is the next one:

npm run test -- --userName=${env:ECASUSER} --password=${env:ECASPWD}

After I start the job the command is called inside the windows agent as expected, triggering the tests. When the test are using those credentials to authenticate it seems they are empty strings. In the job console log, both credentials appear to be there but displayed like this (****).

I have tried a lot of solution none of them work. Am I doing something wrong here?

Upvotes: 0

Views: 873

Answers (2)

Cristian M
Cristian M

Reputation: 357

After some time spent to this, I reached the conclusion that this never worked. Or maybe it did at some point but, yeah it simply stopped. Basically, Jenkins is not passing credentials to Windows batch or Power shell commands. My automation tests were running on blanks.

The only solution, that I found to this problem, is this one:

  1. Create a new binding: Username and Password(conjoined) - here create a new job parameter containing the credentials. Let's say the parameter is named USERPASS;

  2. Create a new 'Windows batch command' section where you save the credentials to a file in you test project (amazingly this one works) - your credentials will be saved to the file like this: "username:password". This is how you save the credentials:

    echo %USERPASS% > "%WORKSPACE%\password.txt"

  3. Change the automation test project to retrieve the credentials from the file;

  4. Delete the file after the tests are completed.

Upvotes: 1

Sergey Pleshakov
Sergey Pleshakov

Reputation: 8948

I believe it should have been

npm run test --userName=${ECASUSER} --password=${ECASPWD}

and make sure you don't pass unnecessary --

Let me know if that doesn't work, I have other ideas

Upvotes: 0

Related Questions