Parametrized Jenkins Job Creation

Hello everybody, while running your automation jobs in Jenkins, you sometimes need to pass some parameters to your scripts. Those parameters can be url, browser name or even the credentials of the test user.  This tutorial will tell you to create a parametrized Jenkins job.

Firstly, I assume you have Jenkins ready in your environment. In case you also want to install Jenkins from scratch you can check below articles.

Prerequisite

When creating a Jenkins job, you should check “This project is parametrized” checkbox

Choice Parameter

You might want your user to be able to select one value among many others. That can be applied to Browsers. You should choose Choice Parameter on the Add Parameter menu. Then you should give a name and fill the values.

String Parameter

You might want your user to change the test environment url or some other value that you in the test. So the user should provide a string value. You should add String Parameter on the Add Parameter menu.

Boolean Parameter

You might want to send a boolean parameter to your test by choosing the Boolean Parameter on the menu. This time you just have to provide a name to it. As the value can be true or false. Jenkins doesn’t allow you to enter a value :)

Password Parameter

In case you need to pass a password parameter to your script, you should use this parameter type as it will be represented by starts and value will stay hidden from all users.

There are many other Parameters that you can provide to your Jenkins Job. Those can be

  • Password Parameter In case you use that one your inout will be represented by starts and hidden from all users.
  • Multi Line String Parameter
  • Git Parameter
  • String Parameter
  • etc…

Then how you will pass all those parameters into your Maven or Gradle command.

How to Use Those Parameters

I’ll show you how to use those parameters in a Gradle build. Same principles apply for both Maven or any other build tool that you might use. You should create a Build Step then choose Invoke Gradle Script. Then you should put the Gradle command and parameters with below structure.

test -DbrowserName="$browser" -DtestUrl="$url"

-DparameterNameInTheSourceCode=”$paramNameInJenkins”

Then you should read that value in the source code. Here’s a small example with Java.

String testUrl = System.getProperty("testUrl");

Happy Testing with Jenkins!

4 thoughts on “Parametrized Jenkins Job Creation”

  1. Hi Canberk,
    Than you for sharing awesome content, can you also please add how to configure file parameter and where the uploaded file stores, how to provide relative path for file parameter. And where the file gets stored once it is ran.

    Reply
  2. Selamlar , bu şekilde kullandığımda Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project : Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test failed: testSuiteXmlFiles0 has null value -> böyle bir hata almaktayım. Bu konu hakkında yardımcı olabilir misiniz.

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.