How do i pass parameters from Jenkins to Ant scripts?

萝らか妹 提交于 2019-12-12 22:06:46

问题


For some GUI testing I'm creating a Jenkins task for each GUI module to be tested. Once created I'm using Ant to build these tests, but I'm not aware of how to actually pass parameters from Jenkins to Ant build file? Basically how do I do variable substitution in Ant?

I'm using the Sahi framework to test GUI components, so the flow goes like this...

Jenkins → Ant build script → Sahi file to execute

Can anyone please take a look at it?


回答1:


"Using ant -Dname=value lets you define values for properties on the Ant command line." http://ant.apache.org/faq.html#passing-cli-args

To use a jenkins parameter as a variable when you call any use ${variablename}

https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build




回答2:


Click Advance under configure section of your job in jenkins and use "Properties" section to pass parameter value to Ant script. e.g

jenkins.param=10 ant.prop=$jenkins.param where jenkins.param is the parameter defined in the jenkins job . Now in your ant build script ,you can get the value by using ${ant.prop}.




回答3:


From Jenkins to SAHI Pro via ANT.

In the ant target that you call from Jenkins, give the following within sahi tag.

  <customfield key="variable_name" value=" variable _value"/>

Now, such values from Jenkins will be available in SAHI Pro through the ant target. To retrieve them in SAHI, you should set them in “CUSTOM_FIELDS” of testrunner file.

For example: SET CUSTOM_FIELDS= -variable_name jenkinsToSahiVariable

Where -variable_name should be same key that you set in ant target. And second string will contain the value you set from Jenkins. To get this in a sahi file, use sahiSuite API like following.

  $jenkinsValues = _suiteInfo();
  $sahiVariable = $ jenkinsValues ["jenkinsToSahiVariable"];


来源:https://stackoverflow.com/questions/10647202/how-do-i-pass-parameters-from-jenkins-to-ant-scripts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!