Forum Discussion

Sanae's avatar
Sanae
Occasional Contributor
4 years ago
Solved

Value on Custom properties not incremented in the remote repository on the master branch

Hello,

 

I use this groovy script to increment variable "increment" that i declared on Custom properties :

 

// read the property as a string
def uniqueUserPortion = testRunner.testCase.testSuite.project.getPropertyValue("increment")
// convert it to an Integer, and increment
def uniqueUserPortionInc = uniqueUserPortion.toInteger() + 1
// set the property back as string
testRunner.testCase.testSuite.project.setPropertyValue("increment", uniqueUserPortionInc.toString())
// check
return testRunner.testCase.testSuite.project.getPropertyValue("increment");


When I launch the script in my local branch, the variable 'increment' is successfully incremented, but when the Jenkins started to run the job automatically on the master branch, the value of the variable 'increment' doesn't change.

So I supposed that the script could not be executed automatically on the master branch. the project on my local branch is the same that I have on the master branch

 

Have you any ideas about that issue? 

Thank you in advance for your response

  • Finally, I found the solution to this issue 🙂. the problem is that we can't modify the File in the remote Git Repository via an automated script launched by Jenkins.
    So I created a file in the System File of the Machine where Jenkins is running in order to update the value of the variable ' increment'. and then I wrote the groovy programme that reads, increments by 1 the value and save it back to the file.
    thanks for your collaboration.

11 Replies

  • Sanae :

     

    What i would suggest is first set the value in project level properties and then do the following task

     

    int increment = 0
    testRunner.testCase.testSuite.project.setPropertyValue("increment",increment.toString())
    // read the property as a string
    def uniqueUserPortion = testRunner.testCase.testSuite.project.getPropertyValue("increment")
    // convert it to an Integer, and increment
    def uniqueUserPortionInc = Integer.parseInt(uniqueUserPortion) + 1
    // set the property back as string
    testRunner.testCase.testSuite.project.setPropertyValue("increment", uniqueUserPortionInc.toString())
    // check
    log.info testRunner.testCase.testSuite.project.getPropertyValue("increment");

     

    • Sanae's avatar
      Sanae
      Occasional Contributor

      each time I run your script I find always the same result because the variable increment is initialized with 0.

      int increment = 0


      Although, I want to retrieve always the last value of the property 'increment' and then increment it by 1.
      Locally my script work fine, but when Jenkins lunch the job the property increment doesn't change.

       

       

       

      • HimanshuTayal's avatar
        HimanshuTayal
        Community Hero

        Sanae :

         

        What was motive was to set the value before retrieving it.

         

        Might be this is causing trouble if Property is not already there in Project level and you try to get it it will throw error so make sure before getting the property it should be there. 

    • Sanae's avatar
      Sanae
      Occasional Contributor

      How are you running the project in Jenkins? Testrunner?

      Answers

      Jenkins executes the project with the maven command "mvn test" but in my local machine I use Testrunner and works fine because I could say the property 'increment' updated in Tab 'Custom properties'. The same project in Jenkins launched with command maven did not change the properties 'increment'? it's due to the configuration of the pom.xml file? Which properties should I add to have the same behavior as test runner.

      • HimanshuTayal's avatar
        HimanshuTayal
        Community Hero

        Sanae :

         

        Do you have specific requirement as you are running it with pom.xml not with testRunner.bat file?