jenkins 使用TestRail UI脚本发送GET/POST请求

vsnjm48y  于 12个月前  发布在  Jenkins
关注(0)|答案(1)|浏览(105)

我试图将TestRail和Jenkins集成在一起,我想使用TestRail UI脚本来创建一个新的按钮。点击这个新按钮时,会向Jenkins发送一个POST请求。
我似乎无法从这个UI脚本发送任何GET/POST请求。我已经尝试过了AZH,XHR,和Fetch,但他们都给我给予错误
Refused to connect to {my_jenkins_url} because it violates the following Content Security Policy directive: "connect-src 'self' https://app.pendo.io https://data.pendo.io https://pendo-static-{...}-.storage.googleapis.com".
我不熟悉ajax和CSP是如何工作的,我看过其他几个关于它的帖子,没有任何东西可以解决我的问题。我需要在TestRail中设置什么吗?还是Jenkins
在Jenkins中,我启用了这些CORS过滤器选项:

Access-Control-Allow-Origins: {my_testrail_url},{my_jenkins_url}
Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS
Access-Control-Allow-Headers: Authorization
Access-Control-Expose-Headers:
Access-Control-Max-Age:

目前,我只是想让它的工作,发送一个GET到Jenkins得到面包屑。以下是我发送请求的方式:

// Bind the click event to trigger the automated tests
    $(myButton).click(
      function() {
        const authToken = btoa(`${JENKINS_USERNAME}:${JENKINS_USER_API_KEY}`);
        var crumbURL = `https://${JENKINS_USERNAME}:${JENKINS_USER_API_KEY}@${JENKINS_URL}crumbIssuer/api/json`
        $.ajax(
          {
            url: crumbURL,
            dateType: "json",
            type: "GET",
            headers: {
              "Authorization" : "Basic " + authToken,
              //"Content-Security-Policy" : `connect-src 'self' ${crumbURL};`
            },
            success: function(data, textStatus, resp) {
              App.Dialogs.message(
                'GET request sent!',
                'Confirmation'
              );
              console.log(data);
            },
            error: function(requestObject, error, errorThrown) {
              console.error(`ERROR sending GET ${crumbURL}`);
              App.Dialogs.message(
                "There was an error retrieving the crumb. Please find more info on the console logs.",
                "Error"
              );
            }
          }
    )
    return false;
      } // end function()
    ); // end .click()
...
...

我发现this UI script on github,但它看起来像它创建了一个额外的登录表单,我希望避免,所以我没有完全复制它。有什么建议吗?TIA!TIA!

dtcbnfnu

dtcbnfnu1#

我们在Gitlab中启动管道的UI脚本也出现了同样的错误,我们不得不进入TestRail中的管理>站点设置>安全,启用“CSP -允许访问TestRail到远程地址”选项,并在字段中列出我们的gitlab URL:Screenshot from TestRail Admin Area

相关问题