日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

如何更新Jenkins作业发布config.xml

發(fā)布時間:2023/12/3 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何更新Jenkins作业发布config.xml 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近,我想更新Cloudbees中的一些作業(yè)(未使用DSL定義),為每個作業(yè)添加一些屬性。

好吧,我在使其工作時遇到了一些麻煩,這是我的注意事項(我使用的是Jenkins 1.651.2.1,但有可能它應與較早和較新的版本一起使用,例如jenkins 2)

沒有安全性/沒有身份驗證

這是簡單的部分:檢索并重新發(fā)布配置

$ curl http://localhost:8080/jenkins/job/pof/config.xml -o config.xml $ curl -X POST http://localhost:8080/jenkins/job/pof/config.xml --data-binary @config.xml

簡單的安全性:使用用戶名和密碼

我現在假設您的Jenkins設置已設置安全性( http:// localhost:8080 / jenkins / configureSecurity / –>啟用安全性)

這意味著我們現在需要驗證我們的兩個請求:

curl -X GET http://anthony:anthony@localhost:8080/jenkins/job/pof/config.xml -o config.xml curl -X POST http://anthony:anthony@localhost:8080/jenkins/job/pof/config.xml --data-binary "@config.xml"

簡單的安全性:啟用CSRF(滾動)

您還需要保護您的jenkins實例免受CSRF攻擊 ( http:// localhost:8080 / jenkins / configureSecurity / –> enable csrf crumb)


現在,這也意味著您的請求需要發(fā)送一個屑狀值,無論是作為參數還是通過標頭

如果您不這樣做:

curl -X POST http://anthony:anthony@localhost:8080/jenkins/job/pof/config.xml --data-binary "@config.xml"

您會得到這樣的錯誤:

<body><h2>HTTP ERROR 403</h2> <p>Problem accessing /jenkins/job/pof/config.xml. Reason: <pre> No valid crumb was included in the request</pre></p><hr /><i><small>Powered by Jetty://</small></i><br/>

甚至 :

<body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>java.io.IOException: Failed to persist config.xml hudson.model.AbstractItem.updateByXml(AbstractItem.java:677) hudson.model.AbstractItem.doConfigDotXml(AbstractItem.java:617) ….. </pre></p><p><b>root cause</b> <pre>javax.xml.transform.TransformerException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file. com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:755) com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:357)jenkins.util.xml.XMLUtils._transform(XMLUtils.java:96)jenkins.util.xml.XMLUtils.safeTransform(XMLUtils.java:63)hudson.model.AbstractItem.updateByXml(AbstractItem.java:674)hudson.model.AbstractItem.doConfigDotXml(AbstractItem.java:617)

獲得面包屑值:

您可以使用configure job頁面來分配值:

curl http://anthony:anthony@localhost:8080/jenkins/job/pof/configure | sed -n 's/.*\.crumb", "\(.*\)").*/\1/p' > crumb.txt

但是,還有專門用于此的服務:

curl http://anthony:anthony@localhost:8080/jenkins/crumbIssuer/api/xml | sed -n 's/.*\(.*\)<\/crumb>.*/\1/p' > crumb.txt

使用面包屑值

curl -X POST http://anthony:anthony@localhost:8080/jenkins/job/pof/config.xml --data-binary "@config.xml" -data ".crumb=6bbabc426436b72ec35e5ad4a4344687"

哎呀,那沒用

Caused by: java.lang.IllegalStateException: STREAMEDat org.eclipse.jetty.server.Request.getReader(Request.java:803)at javax.servlet.ServletRequestWrapper.getReader(ServletRequestWrapper.java:256)at hudson.model.AbstractItem.doConfigDotXml(AbstractItem.java:610)

我建議您使用標題發(fā)送面包屑:

curl -v -X POST http://anthony:anthony@localhost:8080/jenkins/job/pof/config.xml --data-binary "@config.xml" -H ".crumb: 6bbabc426436b72ec35e5ad4a4344687"

基于cookie的安全性(無用戶名/密碼)

在某些安裝中(例如cloubees),您不能在請求中傳遞用戶名和密碼。 我建議您改用cookie。

要檢索它們,請檢查通過身份驗證的瀏覽器發(fā)送的cookie,例如chrome:


然后將此URL粘貼到您的shell中:

curl 'http://localhost:8080/jenkins/job/pof/config.xml' -H 'Pragma: no-cache' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,fr;q=0.6' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://localhost:8080/jenkins/login?from=%2Fjenkins%2Fjob%2Fpof%2Fconfig.xml' -H 'Cookie: screenResolution=1440x900; JSESSIONID=XXXXX; JSESSIONID.XX=XXXX; screenResolution=1440x900' -H 'Connection: keep-alive' -H 'Cache-Control: no-cache' --compressed

當然,您仍然需要獲取面包屑值:

curl 'http://localhost:8080/jenkins/crumbIssuer/api/xml' -H 'Pragma: no-cache' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,fr;q=0.6' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://localhost:8080/jenkins/login?from=%2Fjenkins%2Fjob%2Fpof%2Fconfig.xml' -H 'Cookie: screenResolution=1440x900; JSESSIONID=XXXXX; JSESSIONID.XX=XXXXX; screenResolution=1440x900' -H 'Connection: keep-alive' -H 'Cache-Control: no-cache' --compressed | sed -n 's/.*<crumb>\(.*\)<\/crumb>.*/\1/p' > crumb.txt

現在,您可以發(fā)布更新的config.xml了:

curl -X POST 'http://localhost:8080/jenkins/job/pof/config.xml' -H 'Pragma: no-cache' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,fr;q=0.6' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://localhost:8080/jenkins/login?from=%2Fjenkins%2Fjob%2Fpof%2Fconfig.xml' -H 'Cookie: screenResolution=1440x900; JSESSIONID=XXXX; JSESSIONID.XX=XXXX; screenResolution=1440x900' -H 'Connection: keep-alive' -H 'Cache-Control: no-cache' --compressed --data-binary "@config.xml" -H ".crumb: 6bbabc426436b72ec35e5ad4a4344687"

鏈接

  • https://benkiew.wordpress.com/2012/01/12/automating-hudsonjenkins-via-rest-and-curl-a-very-small-cookbook/
  • https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API

翻譯自: https://www.javacodegeeks.com/2016/05/update-jenkins-job-posting-config-xml.html

總結

以上是生活随笔為你收集整理的如何更新Jenkins作业发布config.xml的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。