原因是在Jenkins 2之后默認開啟CSRF protection (跨域訪問偽造保護),對有些Jenkins API的調用需要提供Jenkins-Crumb;否則會出現”403 No valid crumb was included in the request“ 的錯誤。
獲取Crumb
訪問地址:http://192.168.1.10:8080/crumbIssuer/api/xml
API調用
在customHeaders里面寫入獲取的Crumb值
def response = httpRequest httpMode: 'POST', contentType: 'APPLICATION_JSON', timeout: 3000, requestBody: requestBody, url: url, validResponseCodes: '201', customHeaders: [["Jenkins-Crumb": "a287281b125737f2ef7581fe023d61a7"]], ignoreSslErrors: