我想使用 jenkins 管道在 jira 中创建一个问题,但不使用任何插件,有没有办法这样做?

I want to create an issue in jira using jenkins pipeline but not with any plugin, is there a way to do so?

这是我管道中的阶段的样子

 stage('jira'){
             steps{
           bat 'curl --request POST  --url 'https://ID.atlassian.net/rest/api/2/issue'  --user 'mail@gmail.com:<token>'  --header 'Accept: application/json'  --header 'Content-Type: application/json'  --data '{"fields": {"project":{"key": "FIT"},"summary": "created for j","description": "Created for j","issuetype": {"name": "Task"}}}''
                 }
        }

这是错误的样子

Running in Durability level: MAX_SURVIVABILITY
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 64: expecting '}', found ':'

如果有人知道在管道中实现此目的的任何其他方法,请告诉...

解决方案

嵌套单引号需要使用转义字符。

You can use the Jenkins Syntax generator to produce this. The syntax generator is located at https://< base-url >.com/pipeline-syntax/

stage('jira') {
    steps {
        bat 'curl --request POST  --url \'https://ID.atlassian.net/rest/api/2/issue\'  --user \'mail@gmail.com:<token>\'  --header \'Accept: application/json\'  --header \'Content-Type: application/json\'  --data \'{"fields": {"project":{"key": "FIT"},"summary": "created for j","description": "Created for j","issuetype": {"name": "Task"}}}'
    }
}

这对我有用:)。谢谢。

您需要删除末尾的单个 ',https://himanshu.atlassian.net/rest/api/2/issue/'""" 它将如下所示。使用它并尝试,肯定会起作用。

蝙蝠

curl -D- -u username:token -X POST --data "{\"fields\":{\"project\":{\"key\":\"FIT\"},\"summary\":\"created for j\",\"description\":\"Created for j\",\"issuetype\":{\"name\":\"Task\"}}}" -H "Content-Type: application/json" https://himanshu.atlassian.net/rest/api/2/issue/"""