Jenkins pass parameters to testNG Java












1















I am working on a test automation framework using testNG, Selenium and Jenkins. The code is working fine, it reads one or more csv files and uses that as test data. I run the test from Jenkins.





package test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;

public class runTest {
private WebDriver myDriver = null;

@BeforeTest
public void openBrowser(){
System.out.println("This test automation framework is created by --- for ---");
//Set browser
//System.setProperty("webdriver.chrome.driver", "C://Temp//chromedriver.exe");
//System.setProperty("webdriver.ie.driver", "C://Temp//IEDriverServer.exe");

//Instantiate new WebDriver object with browser of choice
myDriver = new FirefoxDriver();
//myDriver = new InternetExplorerDriver();
//myDriver = new ChromeDriver();
myDriver.get("http://localhost/tests/");
}


@Test (dataProvider="provideData")
public void csvTest(String stepNr, String timeWaitMil, String waitForElement, String clickOnCssNameXpathLink,
String valueInTextBox, String backspaceText, String assertReturnTrueFalse,
String assertBy, String getUrl,
String deleteCookie, String snapshot, String specialSnapshot){



// Click on a something based on css, name xpath or link
if (!"-".equals(clickOnCssNameXpathLink)){
myDriver.findElement(By.name(clickOnCssNameXpathLink)).click();
}

// Enter value in textbox
if (!"-".equals(valueInTextBox)){
myDriver.findElement(By.name(clickOnCssNameXpathLink)).sendKeys(valueInTextBox);
}


// Delete cookies
if (!"-".equals(deleteCookie)){
myDriver.manage().deleteAllCookies();
}

// Make snapshot of whole page
if (snapshot.equalsIgnoreCase("true")){
// take the screenshot of full page
File scrFile = ((TakesScreenshot)myDriver).getScreenshotAs(OutputType.FILE);
// prepare date to use in filename
Date d = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH-mm-ss");
// Save screenshot
try {
FileUtils.copyFile(scrFile, new File("c:\Temp\screenshots\full_page_" +dateFormat.format(d)+ ".png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Could not make screenshot");
}
}

}


@DataProvider
public Iterator<Object > provideData() throws InterruptedException, IOException
{
//Array with multiple csv's
String csvFiles = {"C:/Users/---/Desktop/JES2.0/testingSelenium/testNG/data.csv", "C:/Users/---/Desktop/JES2.0/testingSelenium/testNG/data2.csv"};

List<Object > testCases = new ArrayList<>();

//loop through csv files
for(String csvFile:csvFiles){
String data= null;
//read csv file
BufferedReader br = new BufferedReader(new FileReader(csvFile));

//Skip first line in the csv file, because that only contains the column names
String line = br.readLine();

//loop through csv and split parameters by comma sign ,
while ((line = br.readLine()) != null) {
// use comma as separator
data= line.split(",");
testCases.add(data);
}//end of while loop

}// end of for loop
return testCases.iterator();
}


@AfterTest
public void closeBrowser(){
//close browser
myDriver.quit();
}

}




As you can see, the browser, the url and the CSV files are hardcoded. I want to be able to pass these as parameters. What is the best way to do this? Is it possible to pass them through Jenkins?



I am thinking of building a dashboard where I can specify what tests (csv files) to run using which browser.



This is the Jenkins batch command I am running



java -cp C:Users---DesktopJES2.0testingSeleniumtestNGlibsselenium-server-standalone-2.43.1.jar;C:Users---DesktopJES2.0testingSeleniumtestNGbin org.testng.TestNG testng.xml









share|improve this question



























    1















    I am working on a test automation framework using testNG, Selenium and Jenkins. The code is working fine, it reads one or more csv files and uses that as test data. I run the test from Jenkins.





    package test;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;
    import java.lang.reflect.Method;
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.Iterator;
    import java.util.List;

    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.By;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.ie.InternetExplorerDriver;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.AfterSuite;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.BeforeSuite;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.AfterTest;

    public class runTest {
    private WebDriver myDriver = null;

    @BeforeTest
    public void openBrowser(){
    System.out.println("This test automation framework is created by --- for ---");
    //Set browser
    //System.setProperty("webdriver.chrome.driver", "C://Temp//chromedriver.exe");
    //System.setProperty("webdriver.ie.driver", "C://Temp//IEDriverServer.exe");

    //Instantiate new WebDriver object with browser of choice
    myDriver = new FirefoxDriver();
    //myDriver = new InternetExplorerDriver();
    //myDriver = new ChromeDriver();
    myDriver.get("http://localhost/tests/");
    }


    @Test (dataProvider="provideData")
    public void csvTest(String stepNr, String timeWaitMil, String waitForElement, String clickOnCssNameXpathLink,
    String valueInTextBox, String backspaceText, String assertReturnTrueFalse,
    String assertBy, String getUrl,
    String deleteCookie, String snapshot, String specialSnapshot){



    // Click on a something based on css, name xpath or link
    if (!"-".equals(clickOnCssNameXpathLink)){
    myDriver.findElement(By.name(clickOnCssNameXpathLink)).click();
    }

    // Enter value in textbox
    if (!"-".equals(valueInTextBox)){
    myDriver.findElement(By.name(clickOnCssNameXpathLink)).sendKeys(valueInTextBox);
    }


    // Delete cookies
    if (!"-".equals(deleteCookie)){
    myDriver.manage().deleteAllCookies();
    }

    // Make snapshot of whole page
    if (snapshot.equalsIgnoreCase("true")){
    // take the screenshot of full page
    File scrFile = ((TakesScreenshot)myDriver).getScreenshotAs(OutputType.FILE);
    // prepare date to use in filename
    Date d = new Date();
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH-mm-ss");
    // Save screenshot
    try {
    FileUtils.copyFile(scrFile, new File("c:\Temp\screenshots\full_page_" +dateFormat.format(d)+ ".png"));
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    System.out.println("Could not make screenshot");
    }
    }

    }


    @DataProvider
    public Iterator<Object > provideData() throws InterruptedException, IOException
    {
    //Array with multiple csv's
    String csvFiles = {"C:/Users/---/Desktop/JES2.0/testingSelenium/testNG/data.csv", "C:/Users/---/Desktop/JES2.0/testingSelenium/testNG/data2.csv"};

    List<Object > testCases = new ArrayList<>();

    //loop through csv files
    for(String csvFile:csvFiles){
    String data= null;
    //read csv file
    BufferedReader br = new BufferedReader(new FileReader(csvFile));

    //Skip first line in the csv file, because that only contains the column names
    String line = br.readLine();

    //loop through csv and split parameters by comma sign ,
    while ((line = br.readLine()) != null) {
    // use comma as separator
    data= line.split(",");
    testCases.add(data);
    }//end of while loop

    }// end of for loop
    return testCases.iterator();
    }


    @AfterTest
    public void closeBrowser(){
    //close browser
    myDriver.quit();
    }

    }




    As you can see, the browser, the url and the CSV files are hardcoded. I want to be able to pass these as parameters. What is the best way to do this? Is it possible to pass them through Jenkins?



    I am thinking of building a dashboard where I can specify what tests (csv files) to run using which browser.



    This is the Jenkins batch command I am running



    java -cp C:Users---DesktopJES2.0testingSeleniumtestNGlibsselenium-server-standalone-2.43.1.jar;C:Users---DesktopJES2.0testingSeleniumtestNGbin org.testng.TestNG testng.xml









    share|improve this question

























      1












      1








      1








      I am working on a test automation framework using testNG, Selenium and Jenkins. The code is working fine, it reads one or more csv files and uses that as test data. I run the test from Jenkins.





      package test;
      import java.io.BufferedReader;
      import java.io.File;
      import java.io.FileReader;
      import java.io.IOException;
      import java.lang.reflect.Method;
      import java.text.SimpleDateFormat;
      import java.util.ArrayList;
      import java.util.Date;
      import java.util.Iterator;
      import java.util.List;

      import org.apache.commons.io.FileUtils;
      import org.openqa.selenium.By;
      import org.openqa.selenium.OutputType;
      import org.openqa.selenium.TakesScreenshot;
      import org.openqa.selenium.WebDriver;
      import org.openqa.selenium.chrome.ChromeDriver;
      import org.openqa.selenium.firefox.FirefoxDriver;
      import org.openqa.selenium.ie.InternetExplorerDriver;
      import org.testng.annotations.AfterClass;
      import org.testng.annotations.AfterMethod;
      import org.testng.annotations.AfterSuite;
      import org.testng.annotations.BeforeClass;
      import org.testng.annotations.BeforeMethod;
      import org.testng.annotations.BeforeSuite;
      import org.testng.annotations.DataProvider;
      import org.testng.annotations.Test;
      import org.testng.annotations.BeforeTest;
      import org.testng.annotations.AfterTest;

      public class runTest {
      private WebDriver myDriver = null;

      @BeforeTest
      public void openBrowser(){
      System.out.println("This test automation framework is created by --- for ---");
      //Set browser
      //System.setProperty("webdriver.chrome.driver", "C://Temp//chromedriver.exe");
      //System.setProperty("webdriver.ie.driver", "C://Temp//IEDriverServer.exe");

      //Instantiate new WebDriver object with browser of choice
      myDriver = new FirefoxDriver();
      //myDriver = new InternetExplorerDriver();
      //myDriver = new ChromeDriver();
      myDriver.get("http://localhost/tests/");
      }


      @Test (dataProvider="provideData")
      public void csvTest(String stepNr, String timeWaitMil, String waitForElement, String clickOnCssNameXpathLink,
      String valueInTextBox, String backspaceText, String assertReturnTrueFalse,
      String assertBy, String getUrl,
      String deleteCookie, String snapshot, String specialSnapshot){



      // Click on a something based on css, name xpath or link
      if (!"-".equals(clickOnCssNameXpathLink)){
      myDriver.findElement(By.name(clickOnCssNameXpathLink)).click();
      }

      // Enter value in textbox
      if (!"-".equals(valueInTextBox)){
      myDriver.findElement(By.name(clickOnCssNameXpathLink)).sendKeys(valueInTextBox);
      }


      // Delete cookies
      if (!"-".equals(deleteCookie)){
      myDriver.manage().deleteAllCookies();
      }

      // Make snapshot of whole page
      if (snapshot.equalsIgnoreCase("true")){
      // take the screenshot of full page
      File scrFile = ((TakesScreenshot)myDriver).getScreenshotAs(OutputType.FILE);
      // prepare date to use in filename
      Date d = new Date();
      SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH-mm-ss");
      // Save screenshot
      try {
      FileUtils.copyFile(scrFile, new File("c:\Temp\screenshots\full_page_" +dateFormat.format(d)+ ".png"));
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      System.out.println("Could not make screenshot");
      }
      }

      }


      @DataProvider
      public Iterator<Object > provideData() throws InterruptedException, IOException
      {
      //Array with multiple csv's
      String csvFiles = {"C:/Users/---/Desktop/JES2.0/testingSelenium/testNG/data.csv", "C:/Users/---/Desktop/JES2.0/testingSelenium/testNG/data2.csv"};

      List<Object > testCases = new ArrayList<>();

      //loop through csv files
      for(String csvFile:csvFiles){
      String data= null;
      //read csv file
      BufferedReader br = new BufferedReader(new FileReader(csvFile));

      //Skip first line in the csv file, because that only contains the column names
      String line = br.readLine();

      //loop through csv and split parameters by comma sign ,
      while ((line = br.readLine()) != null) {
      // use comma as separator
      data= line.split(",");
      testCases.add(data);
      }//end of while loop

      }// end of for loop
      return testCases.iterator();
      }


      @AfterTest
      public void closeBrowser(){
      //close browser
      myDriver.quit();
      }

      }




      As you can see, the browser, the url and the CSV files are hardcoded. I want to be able to pass these as parameters. What is the best way to do this? Is it possible to pass them through Jenkins?



      I am thinking of building a dashboard where I can specify what tests (csv files) to run using which browser.



      This is the Jenkins batch command I am running



      java -cp C:Users---DesktopJES2.0testingSeleniumtestNGlibsselenium-server-standalone-2.43.1.jar;C:Users---DesktopJES2.0testingSeleniumtestNGbin org.testng.TestNG testng.xml









      share|improve this question














      I am working on a test automation framework using testNG, Selenium and Jenkins. The code is working fine, it reads one or more csv files and uses that as test data. I run the test from Jenkins.





      package test;
      import java.io.BufferedReader;
      import java.io.File;
      import java.io.FileReader;
      import java.io.IOException;
      import java.lang.reflect.Method;
      import java.text.SimpleDateFormat;
      import java.util.ArrayList;
      import java.util.Date;
      import java.util.Iterator;
      import java.util.List;

      import org.apache.commons.io.FileUtils;
      import org.openqa.selenium.By;
      import org.openqa.selenium.OutputType;
      import org.openqa.selenium.TakesScreenshot;
      import org.openqa.selenium.WebDriver;
      import org.openqa.selenium.chrome.ChromeDriver;
      import org.openqa.selenium.firefox.FirefoxDriver;
      import org.openqa.selenium.ie.InternetExplorerDriver;
      import org.testng.annotations.AfterClass;
      import org.testng.annotations.AfterMethod;
      import org.testng.annotations.AfterSuite;
      import org.testng.annotations.BeforeClass;
      import org.testng.annotations.BeforeMethod;
      import org.testng.annotations.BeforeSuite;
      import org.testng.annotations.DataProvider;
      import org.testng.annotations.Test;
      import org.testng.annotations.BeforeTest;
      import org.testng.annotations.AfterTest;

      public class runTest {
      private WebDriver myDriver = null;

      @BeforeTest
      public void openBrowser(){
      System.out.println("This test automation framework is created by --- for ---");
      //Set browser
      //System.setProperty("webdriver.chrome.driver", "C://Temp//chromedriver.exe");
      //System.setProperty("webdriver.ie.driver", "C://Temp//IEDriverServer.exe");

      //Instantiate new WebDriver object with browser of choice
      myDriver = new FirefoxDriver();
      //myDriver = new InternetExplorerDriver();
      //myDriver = new ChromeDriver();
      myDriver.get("http://localhost/tests/");
      }


      @Test (dataProvider="provideData")
      public void csvTest(String stepNr, String timeWaitMil, String waitForElement, String clickOnCssNameXpathLink,
      String valueInTextBox, String backspaceText, String assertReturnTrueFalse,
      String assertBy, String getUrl,
      String deleteCookie, String snapshot, String specialSnapshot){



      // Click on a something based on css, name xpath or link
      if (!"-".equals(clickOnCssNameXpathLink)){
      myDriver.findElement(By.name(clickOnCssNameXpathLink)).click();
      }

      // Enter value in textbox
      if (!"-".equals(valueInTextBox)){
      myDriver.findElement(By.name(clickOnCssNameXpathLink)).sendKeys(valueInTextBox);
      }


      // Delete cookies
      if (!"-".equals(deleteCookie)){
      myDriver.manage().deleteAllCookies();
      }

      // Make snapshot of whole page
      if (snapshot.equalsIgnoreCase("true")){
      // take the screenshot of full page
      File scrFile = ((TakesScreenshot)myDriver).getScreenshotAs(OutputType.FILE);
      // prepare date to use in filename
      Date d = new Date();
      SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH-mm-ss");
      // Save screenshot
      try {
      FileUtils.copyFile(scrFile, new File("c:\Temp\screenshots\full_page_" +dateFormat.format(d)+ ".png"));
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      System.out.println("Could not make screenshot");
      }
      }

      }


      @DataProvider
      public Iterator<Object > provideData() throws InterruptedException, IOException
      {
      //Array with multiple csv's
      String csvFiles = {"C:/Users/---/Desktop/JES2.0/testingSelenium/testNG/data.csv", "C:/Users/---/Desktop/JES2.0/testingSelenium/testNG/data2.csv"};

      List<Object > testCases = new ArrayList<>();

      //loop through csv files
      for(String csvFile:csvFiles){
      String data= null;
      //read csv file
      BufferedReader br = new BufferedReader(new FileReader(csvFile));

      //Skip first line in the csv file, because that only contains the column names
      String line = br.readLine();

      //loop through csv and split parameters by comma sign ,
      while ((line = br.readLine()) != null) {
      // use comma as separator
      data= line.split(",");
      testCases.add(data);
      }//end of while loop

      }// end of for loop
      return testCases.iterator();
      }


      @AfterTest
      public void closeBrowser(){
      //close browser
      myDriver.quit();
      }

      }




      As you can see, the browser, the url and the CSV files are hardcoded. I want to be able to pass these as parameters. What is the best way to do this? Is it possible to pass them through Jenkins?



      I am thinking of building a dashboard where I can specify what tests (csv files) to run using which browser.



      This is the Jenkins batch command I am running



      java -cp C:Users---DesktopJES2.0testingSeleniumtestNGlibsselenium-server-standalone-2.43.1.jar;C:Users---DesktopJES2.0testingSeleniumtestNGbin org.testng.TestNG testng.xml






      java selenium parameters jenkins testng






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Oct 15 '14 at 10:26









      StudentStudent

      1912625




      1912625
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Jenkins have a built-in parameters handling, which is quite flexible in it's own way. But in this case, since you want to pass a filename as parameter, you can easily combine that functionality with a Filesystem List Parameter, which can build the list based on a regexp that will parse list of files.



          If you use Maven or Ant, you can embed that parameter within your build process, in a form similar to this:



            <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
          <systemPropertyVariables>
          <environment>${env.PARAM}</environment>
          </systemPropertyVariables>
          <suiteXmlFiles>
          <suiteXmlFile>testng.xml</suiteXmlFile>
          </suiteXmlFiles>
          </configuration>
          </plugin>


          With this you can read the parameter that was passed on to Maven - in Jenkins using it's internal caller, and on command line with:



          mvn install -Denv.PARAM=VALUE


          So it should work either way...






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f26380231%2fjenkins-pass-parameters-to-testng-java%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Jenkins have a built-in parameters handling, which is quite flexible in it's own way. But in this case, since you want to pass a filename as parameter, you can easily combine that functionality with a Filesystem List Parameter, which can build the list based on a regexp that will parse list of files.



            If you use Maven or Ant, you can embed that parameter within your build process, in a form similar to this:



              <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
            <systemPropertyVariables>
            <environment>${env.PARAM}</environment>
            </systemPropertyVariables>
            <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
            </suiteXmlFiles>
            </configuration>
            </plugin>


            With this you can read the parameter that was passed on to Maven - in Jenkins using it's internal caller, and on command line with:



            mvn install -Denv.PARAM=VALUE


            So it should work either way...






            share|improve this answer




























              1














              Jenkins have a built-in parameters handling, which is quite flexible in it's own way. But in this case, since you want to pass a filename as parameter, you can easily combine that functionality with a Filesystem List Parameter, which can build the list based on a regexp that will parse list of files.



              If you use Maven or Ant, you can embed that parameter within your build process, in a form similar to this:



                <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-surefire-plugin</artifactId>
              <configuration>
              <systemPropertyVariables>
              <environment>${env.PARAM}</environment>
              </systemPropertyVariables>
              <suiteXmlFiles>
              <suiteXmlFile>testng.xml</suiteXmlFile>
              </suiteXmlFiles>
              </configuration>
              </plugin>


              With this you can read the parameter that was passed on to Maven - in Jenkins using it's internal caller, and on command line with:



              mvn install -Denv.PARAM=VALUE


              So it should work either way...






              share|improve this answer


























                1












                1








                1







                Jenkins have a built-in parameters handling, which is quite flexible in it's own way. But in this case, since you want to pass a filename as parameter, you can easily combine that functionality with a Filesystem List Parameter, which can build the list based on a regexp that will parse list of files.



                If you use Maven or Ant, you can embed that parameter within your build process, in a form similar to this:



                  <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                <systemPropertyVariables>
                <environment>${env.PARAM}</environment>
                </systemPropertyVariables>
                <suiteXmlFiles>
                <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
                </configuration>
                </plugin>


                With this you can read the parameter that was passed on to Maven - in Jenkins using it's internal caller, and on command line with:



                mvn install -Denv.PARAM=VALUE


                So it should work either way...






                share|improve this answer













                Jenkins have a built-in parameters handling, which is quite flexible in it's own way. But in this case, since you want to pass a filename as parameter, you can easily combine that functionality with a Filesystem List Parameter, which can build the list based on a regexp that will parse list of files.



                If you use Maven or Ant, you can embed that parameter within your build process, in a form similar to this:



                  <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                <systemPropertyVariables>
                <environment>${env.PARAM}</environment>
                </systemPropertyVariables>
                <suiteXmlFiles>
                <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
                </configuration>
                </plugin>


                With this you can read the parameter that was passed on to Maven - in Jenkins using it's internal caller, and on command line with:



                mvn install -Denv.PARAM=VALUE


                So it should work either way...







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Oct 15 '14 at 11:55









                Łukasz RżanekŁukasz Rżanek

                5,0272037




                5,0272037
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f26380231%2fjenkins-pass-parameters-to-testng-java%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas