我使用参数FRACTURE_NO = 15
触发名为 testAUT 的构建。我使用相同的参数触发相同的构建。
我希望当发生这种情况时,早期版本会被杀死。我怎么能用Jenkins做到这一点?我希望能够使用与当前版本相同的参数结束构建。
答案 0 :(得分:1)
如果您使用Groovy Plugin和Jenkins Rest Api即可,请执行以下步骤:
def parameterName = "fracture_no";
def jenkinsUrl = System.getenv('JENKINS_URL');
def buildNumber = System.getenv('BUILD_NUMBER').toInteger();
def jobUrl = jenkinsUrl + "job/" + System.getenv('JOB_NAME');
def buildNumberUrl = jobUrl + "/" + buildNumber;
def myParameter = System.getenv(parameterName);
def projectXml = new XmlSlurper().parseText(new URL(jobUrl + "/api/xml").getText());
projectXml.build.each {
def previousBuildNumber = it.number.text().toInteger();
if(previousBuildNumber < buildNumber)
{
def previousBuildNumberUrl = jobUrl + "/" + previousBuildNumber;
def jobXml = new XmlSlurper().parseText(new URL(previousBuildNumberUrl + "/api/xml").getText());
if(jobXml.building.text() == "true")
{
jobXml.action.parameter.each {
if(it.name.text() == parameterName) {
if(it.value.text() == myParameter) {
def url = new URL(previousBuildNumberUrl + "/stop");
def connection = url.openConnection();
connection.setRequestMethod("POST");
connection.connect();
connection.content.text;
println "Stopping " + previousBuildNumber;
}
}
}
}
}
}
ping 127.0.0.1 -n 100 > nul