从 Jira Xray 问题触发 Jenkins 构建

Trigger Jenkins Build from Jira Xray Issue

我指的是 Xray 文档中的 Trigger a Jenkins project build from a Test Plan 从 Jira 问题触发 Jenkins 构建。在设置自定义 Web 项目时,我应该指向什么 link?我刚刚从文档中复制了 link。

在 REST 端点设置中,我在 requestMethod、getResponseCode() 和 getResponseMessage() 方法上遇到错误

我不确定 ScriptRunner 执行历史是否也没有显示完整的负载信息。

Jira DC v8.9.0
ScriptRunner v6.51.0
Xray v6.1.3
詹金斯 v2.263.1

非常感谢任何帮助!

问题是由于 UrlConnection class 的弃用造成的。 您应该更新代码以改为使用 HttpURLConnection class。可能是这样的:

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonOutput
import groovy.transform.BaseScript
import groovy.json.StreamingJsonBuilder;
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import java.net.HttpURLConnection
  
@BaseScript CustomEndpointDelegate delegate
  
triggerJenkinsBuild(httpMethod: "GET") { MultivaluedMap queryParams ->
  
    def issueId = queryParams.getFirst("issueId") as String // use the issueId to retrieve this issue
      
    def flag = [
    type : 'success',
    title: "Build scheduled",
    close: 'auto',
    body : "A new build has been scheduled related with "+issueId
    ]
    
 
    URL url;
    def jobName = "java-junit-calc"                         // could come from a CF in the Test Plan
    def jenkinsHostPort = "192.168.56.102:8081"             // could be defined elsewhere
    def token = "iFBDOBhNhaxL4T9ass93HRXun2JF161Z"          // could also come from a CF in the Test Plan
    def username = "admin"                                  // probably, would need to be stored elsewhere
    def password = "fa02840152aa2e4da3d8db933ec708d6"       // probably, would need to be stored elsewhere
    def baseURL = "http://${jenkinsHostPort}/job/${jobName}/buildWithParameters?token=${token}&TESTPLAN=$issueId"
 
    url = new URL(baseURL);
    def body_req = []
 
    def authString = "${username}:${password}".bytes.encodeBase64().toString()
 
    HttpURLConnection connection = (HttpURLConnection) url.openConnection()
    connection.setRequestMethod("POST")
    connection.setDoOutput(true)
    connection.addRequestProperty("Authorization", "Basic ${authString}")
    connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8")
    connection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, body_req) }
    connection.connect();
    log.debug(connection.getResponseCode())
    log.debug(connection.getResponseMessage())
 
     
    if (connection.getResponseCode() == 201) {
        Response.ok(JsonOutput.toJson(flag)).build()
    } else {
        //Response.status(Response.Status.NOT_FOUND).entity("Problem scheduling job!").build();
    }
     
}