簡體   English   中英

從 Jenkins 創建 Jira 問題

[英]Create Jira issue from Jenkins

嗨,我正在嘗試通過 windows 從站上的 Jenkins 創建 Jira 問題。 控制台 output 沒有顯示任何錯誤,但是沒有創建 Jira 問題。 下面是代碼:

pipeline {
  agent { label 'windows'}
   stages {
    stage('Build') {
     steps {  
       bat script {"""curl -u ${jira_username}:${jira_password} -X POST -H 'Content- Type:application/json' -d '{"fields":{"components":[{"id":"1"}],"fixVersions":[{"id":"2"}],"project":{"key":"KEY"},"summary":"summary","description":"description","issuetype":{"name":"Test"}}}' http://localhost:8080/rest/api/2/issue/"""}
    }
  }
}

}

控制台 output 是:

 D:\workspace\TestJob>curl -u username:password -X POST -H 'Content-Type:application/json' -d 
'{"fields":{"components":[{"id":"1"}],"fixVersions":[{"id":"2"}],"project": 
{"key":"KEY"},"summary":"summary","description":"description","issuetype":{"name":"Test"}}}' 
http://localhost:8080/rest/api/2/issue/ 
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
 100   136    0     0  100   136      0    323 --:--:-- --:--:-- --:--:--   326

它不會引發任何錯誤,但問題也不會被創建。

但是,如果我在 Linux 從機上運行相同的代碼,那么我會得到以下響應並且問題正在被創建。

  + curl -u 'username:password' -X POST -H Content-Type:application/json -d '{"fields": 
  {"components":[{"id":"1"}],"fixVersions":[{"id":"2"}],"project": 
  {"key":"KEY"},"summary":"summary","description":"description","issuetype": 
  {"name":"Test"}}}' http://localhost:8080/rest/api/2/issue/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
 100   255    0    87  100   168    115    223 --:--:-- --:--:-- --:--:--   223
 100   255    0    87  100   168    115    223 --:--:-- --:--:-- --:--:--   223
 {"id":"648","key":"KEY-35","self":"http://localhost:8080/rest/api/2/issue/648"}

如您所見,問題是在 Linux 上產生的,但在 windows 上沒有。 請求幫助以解決此問題。

解決了這個問題

首先,'Content-Type: application/json'應該用雙引號括起來。 將它放在單引號'Content-Type:application / json'中實際上給出了415錯誤代碼,我在curl命令中使用-k -D-后才知道

其次,我不得不在數據中使用雙反斜杠。

實際工作的命令是:

bat script {"""curl -u username:password --header "Content-Type:application/json" -X POST --data "{\\"fields\\":{\\"project\\":{\\"key\\":\\"KEY\\"},\\"summary\\":\\"summary\\",\\"description\\":\\"description\\",\\"issuetype\\":{\\"name\\":\\"Test\\"},\\"components\\":[{\\"id\\":\\"1\\"}],\\"fixVersions\\":[{\\"id\\":\\"2\\"}]}}" http://localhost:8080/rest/api/2/issue/"""}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM