我想了解如何将参数传递给jenkins的maven项目。 首先,我选择了一般配置在詹金斯,并单击 “这个项目是参数化”,那么如何将参数传递给jenkins的maven项目
名称=> my_parameter
选择=>桌面, 的ipad, 平板
然后,源管理=>混帐我写的git repo链接的仓库,它是确定的。
末步的构建=>执行shell =>命令=> MVN测试-DdeviceType = $ my_parameter
我的Maven项目有一个参数命名字符串设备。
String device;
public static DesiredCapabilities caps=null;
@BeforeSuite
public void initializeDriver() throws MalformedURLException{
device=System.getenv("deviceType");
System.out.println("device type: "+ device);
if (device.contains("ipad")) {
caps = new DesiredCapabilities();
caps.setCapability("browserName", "iPad");
caps.setCapability("platform", "MAC");
caps.setCapability("device", "iPad Mini 4");
caps.setCapability("browserstack.local", "true");
caps.setCapability("browserstack.debug", "true");
caps.setCapability("safariAllowPopups", "true");
caps.setCapability("acceptSslCerts", "true");
caps.setCapability("browserstack.autoWait", "0");
caps.setCapability("requireWindowFocus", "true");
driver=new RemoteWebDriver(new URL(URL), caps);
}
然后与詹金斯参数建立
$ /bin/sh -xe /var/folders/j9/gyf9715j0hs32m4gd8h_gw4m55zss4 /T/hudson7304038831620598368.sh
+ mvn test -DdeviceType=desktop
[INFO] Scanning for projects...
device type: null[0m
为什么设备类型返回NULL?怎么了? 感谢您的帮助...
我试过device = System.getProperty(“deviceType”); System.out.println(“device type:”+ device); 没有区别。设备类型返回null –
这是因为提供给mvn的系统道具不会转换为可用于基于surefire的单元测试的系统属性。如果您仍想使用系统属性(最好使用env vars),请参阅http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html了解如何设置surefire系统属性。 –