我想了解如何將參數傳遞給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系統屬性。 –