如题:
就是在 Manage jenkins -> Configure Global Security -> 跨站请求伪造保护 这个没有勾选框啊,咋办??
无法勾选这会导致,使用 jenkinsapi 调用,build_job 时会报错
jenkinsapi.custom_exceptions.JenkinsAPIException: Operation failed. url=http://ci.test.com/jenkins/job/test_job_name/build, data={'json': '{"parameter": [], "statusCode": "303", "redirectTo": "."}'}, headers={'Content-Type': 'application/x-www-form-urlencoded', 'Jenkins-Crumb': '42a52abd17c6bf259171d23c5ab84018cfd024f1d319fe0d249c2955680382d5'}, status=403, text=b'<!doctype html><html lang="en"><head><title>HTTP Status 403 \xe2\x80\x93 Forbidden</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 403 \xe2\x80\x93 Forbidden</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> No valid crumb was included in the request</p><p><b>Description</b> The server understood the request but refuses to authorize it.</p><hr class="line" /><h3>Apache Tomcat/8.5.34</h3></body></html>'
触发构建脚本:
def build_job(job_name = "test_job_name"):
from jenkinsapi.utils.crumb_requester import CrumbRequester
j = Jenkins(URL, username=JENKINS_USER, password=JENKINS_PASSWORD, requester=CrumbRequester(username=JENKINS_USER, password=JENKINS_PASSWORD, baseurl=URL))
# j = Jenkins(URL, username=JENKINS_USER, password=JENKINS_PASSWORD)
# j[job_name].invoke()
print(j.build_job(job_name))
return True
我另外一个 jenkins v2.150.3 是可以的,有勾选框
有哪位大佬知道肿么回事么?