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

jenkins如何从jenkins gradle运行指定testng.xml,jenkins,gradle,automation,Jenkins,Gradle,Automation,我正在与jenkins合作,尝试调用一台远程机器,该机器有一个带有gradle config的java项目来运行tests build.gradle 版本“1.0-SNAPSHOT” apply plugin: 'idea' apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'maven-publish' sourceCompatibility = 1.8 version = '1.0' sourceSets {

我正在与jenkins合作,尝试调用一台远程机器,该机器有一个带有gradle config的java项目来运行tests build.gradle 版本“1.0-SNAPSHOT”

apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

sourceCompatibility = 1.8
version = '1.0'


sourceSets {
    jars
}

repositories {
    jcenter()
    mavenCentral()
}

dependencies {
    compile fileTree(dir: "src/jars/resources", include: ['*.jar'])
    compile group: 'org.testng', name: 'testng', version: '6.9.10'
    compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.+'
    compile group: 'io.appium', name: 'java-client', version: '4.1.2'
    compile 'com.testdroid:testdroid-api:2.9'
    compile group: 'org.json', name: 'json', version: '20141113'
}

compileJava {
    options.encoding = "UTF-8"
}

test {
    useTestNG {
        suites 'src/main/resources/testng.xml'
    }
}
但是我想运行一个定制的testng2.xml!因此,我在jenkins中定义了一个参数测试,并定义了它们的testng2.xml,但它将显示在控制台中

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

但是我不明白如何让gradle获得动态参数,像那样使用它,默认值设置为
testng.xml

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

test {
    useTestNG {
        suites "src/main/resources/$testFile"
    }
}
/Users/jenkins/Home/workspace/AutomationGradle/gradlew -DTest_Plan=testng2.xml  clean test -i
并使用
test
参数运行命令行

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

这样使用它,默认值设置为
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

谢谢你,我在这方面花了很多时间,所以我在写我的作品:

在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
 }
}

谢谢你,我在这方面花了很多时间,所以我在写我的作品:

在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
 }
}

这是正确的答案。理想情况下,添加命令行用法,pleasestill由于某种原因无法工作总是转到“testng.xml”,什么是“ext”?我需要更多infoext.testFile=System.getProperty('Test_Plan')?:'testng.xml'Test{useTestNG{suites”src/main/resources/${testFile}}}请将项目更改为System,因为我发送的是-D参数而不是-P,并将{}添加到testFile@ToYonosEdited。但是使用项目属性应该更好,不是吗?这是正确的答案。理想情况下,添加命令行用法,pleasestill由于某种原因无法工作总是转到“testng.xml”,什么是“ext”?我需要更多infoext.testFile=System.getProperty('Test_Plan')?:'testng.xml'Test{useTestNG{suites”src/main/resources/${testFile}}}请将项目更改为System,因为我发送的是-D参数而不是-P,并将{}添加到testFile@ToYonosEdited。但是使用项目属性应该更好,不是吗?