jenkins如何从jenkins gradle运行指定testng.xml

时间:2017-06-15 14:44:48

标签: jenkins gradle automation

我正在使用jenkins并尝试调用一个带有gradle配置的java项目的远程计算机来运行测试build.gradle 版本'1.0-SNAPSHOT'

/Users/jenkins/Home/workspace/AutomationGradle/gradlew -Dtest=testng2.xml  clean test -i

但我想运行自定义的testng2.xml!所以我在jenkins中定义了一个参数测试并定义了他们的testng2.xml,但它会在控制台中显示

var uid = "";
var token = "";

$.ajax({
    type: "POST",
    url: "http://www.example.com/apis/login.php",
    data: JSON.stringify(inputs),
    dataType: "json",
    success: function(data) {
        if(data.status == "success") {
            uid = data.uid;
            token = decodeURIComponent(data.token);
            successCallback();
        }
        else{
            alert(data.message);
        }
    },
    error: function() {
        alert("could not connect to server");
    }
});


function successCallback()
{
    document.getElementById("user-id").innerHTML = uid;
    $.ajax({
        type: "GET",
        url: "http://www.example.com/apis/services.php",
        headers: {
            "Auth-Token" : encodeURIComponent(token),
            "U-Id" : uid
        },
        success: function(data) {
            alert("connected to server");
        },
        error: function() {
            alert("could not connect to server");
        }
    }); 
}

但我无法理解如何让gradle获取动态参数

2 个答案:

答案 0 :(得分:2)

使用它,默认值设置为testng.xml

ext.testFile = System.getProperty('Test_Plan') ?: 'testng.xml'

test {
    useTestNG {
        suites "src/main/resources/$testFile"
    }
}

使用test参数

运行命令行
/Users/jenkins/Home/workspace/AutomationGradle/gradlew -DTest_Plan=testng2.xml  clean test -i

答案 1 :(得分:0)

谢谢,我为此花了很多时间,所以我正在写对我有用的东西:

在Jeninks中,我添加了一个参数:     TESTNGFILE

In the groovy file:    
-DTestNG=$TESTNGFILE

build.gradle:

ext.testFile = System.getProperty('TestNG') ?: 'regression.xml'


test {
useTestNG {
    options {
        systemProperties(System.getProperties())
    }
    systemProperties = [
            TESTNGFILE: System.getProperty('TESTNGFILE')
    ]
    suites "/src/test/resources/testng/${testFile}"
    testLogging.showStandardStreams = true
    useDefaultListeners = true
 }
}