cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Highlighted
Occasional Contributor

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

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Occasional Contributor

Re: Solution

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.

View solution in original post

11 REPLIES 11
Highlighted
Community Leader

Re: Value on Custom properties not incremented in the remote repository on the master branche

@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");

 


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Highlighted
Occasional Contributor

Re: Value on Custom properties not incremented in the remote repository on the master branche

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.

 

 

 

Highlighted
Community Leader

Re: Value on Custom properties not incremented in the remote repository on the master branche

@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. 


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Highlighted
Occasional Contributor

Re: Value on Custom properties not incremented in the remote repository on the master branche

Hello,

i try to use your code by setting value in the fist like that :

def increment = context.expand( '${#Project#increment}' );
testRunner.testCase.testSuite.project.setPropertyValue("increment",increment.toString());
def uniqueUserPortion = testRunner.testCase.testSuite.project.getPropertyValue("increment");
def uniqueUserPortionInc = Integer.parseInt(uniqueUserPortion) + 1;
testRunner.testCase.testSuite.project.setPropertyValue("increment", uniqueUserPortionInc.toString());
return testRunner.testCase.testSuite.project.getPropertyValue("increment");

but i change the firt line because i need to recover the last value that i put on Cutum properties : 

Custom Property.PNG

But I still have the same issue: When I launched my project locally on ReadyAPI the value is increased by one, but when I commit my script on the git then i try to launch the project in Jenkins the value doesn't incremented.

 

Highlighted
Community Leader

Re: Value on Custom properties not incremented in the remote repository on the master branche

@Sanae :

 

What i would suggest is :

 

1. delete the custom property from project level before running (in local machine).

2. If it still run on your local machine then please share error log of jenkins, i will try to dig in more.

 

As it should run on jenkins as it is running on your local, please send the sample project if possible for you.


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Highlighted
Community Hero

Re: Value on Custom properties not incremented in the remote repository on the master branche

How are you running the project in jenkins? Testrunner?
Can you try the test using testrunner and see if it is reproducible the issue from the tool.
Refer below documentation for the same.
https://support.smartbear.com/readyapi/docs/soapui/running/automating/gui.html


Regards,
Rao.
Highlighted
Occasional Contributor

Re: Value on Custom properties not incremented in the remote repository on the master branche

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.

Highlighted
Community Leader

Re: Value on Custom properties not incremented in the remote repository on the master branche

@Sanae :

 

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

 


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Highlighted
Occasional Contributor

Re: Value on Custom properties not incremented in the remote repository on the master branche

The project is already integrated remotely in Jenkins and it's running with maven command. I'm not, the administrator of Jenkins and I cannot modify the current configuration.
locally on my machine I could use the test runner with testrunner.bat and that works fine

New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
Let's start July with new challenges!

Create a script to change request body before sending it to the server for the TechCorner tag!


Scripts created in June:
- A script to generate a request body based on data from Datasource
- A script to go through all response nodes and check the value of the required field
- A Dispatching script to get responses based on the values in Request Body
- A script to add a new tag and assign it to all TestCases in a TestSuite
Top Kudoed Authors