mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-30 05:59:39 +02:00
githubPublishRelease - ensure proper JSON encoding (#807)
So far some special characters have not been properly encoded when creating a release. This is addressed by using a new JsonUtils method now.
This commit is contained in:
parent
e8821c2b90
commit
153dbf2a7f
@ -7,6 +7,11 @@ String groovyObjectToPrettyJsonString(object) {
|
|||||||
return groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(object))
|
return groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(object))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonCPS
|
||||||
|
String groovyObjectToJsonString(object) {
|
||||||
|
return groovy.json.JsonOutput.toJson(object)
|
||||||
|
}
|
||||||
|
|
||||||
@NonCPS
|
@NonCPS
|
||||||
def jsonStringToGroovyObject(text) {
|
def jsonStringToGroovyObject(text) {
|
||||||
return new groovy.json.JsonSlurperClassic().parseText(text)
|
return new groovy.json.JsonSlurperClassic().parseText(text)
|
||||||
|
@ -213,4 +213,5 @@ class GithubPublishReleaseTest extends BasePiperTest {
|
|||||||
assertThat(stepRule.step.isExcluded(item, ['won\'t fix']), is(false))
|
assertThat(stepRule.step.isExcluded(item, ['won\'t fix']), is(false))
|
||||||
assertJobStatusSuccess()
|
assertJobStatusSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import com.sap.piper.JsonUtils
|
||||||
|
|
||||||
import static com.sap.piper.Prerequisites.checkScript
|
import static com.sap.piper.Prerequisites.checkScript
|
||||||
|
|
||||||
import com.sap.piper.GenerateDocumentation
|
import com.sap.piper.GenerateDocumentation
|
||||||
@ -146,9 +148,15 @@ String addDeltaToLastRelease(config, latestTag){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void postNewRelease(config, TOKEN, releaseBody){
|
void postNewRelease(config, TOKEN, releaseBody){
|
||||||
releaseBody = releaseBody.replace('"', '\\"')
|
Map messageBody = [
|
||||||
//write release information
|
tag_name: "${config.version}",
|
||||||
def data = "{\"tag_name\": \"${config.version}\",\"target_commitish\": \"master\",\"name\": \"${config.version}\",\"body\": \"${releaseBody}\",\"draft\": false,\"prerelease\": false}"
|
target_commitish: 'master',
|
||||||
|
name: "${config.version}",
|
||||||
|
body: releaseBody,
|
||||||
|
draft: false,
|
||||||
|
prerelease: false
|
||||||
|
]
|
||||||
|
def data = new JsonUtils().groovyObjectToJsonString(messageBody)
|
||||||
try {
|
try {
|
||||||
httpRequest httpMode: 'POST', requestBody: data, url: "${config.githubApiUrl}/repos/${config.githubOrg}/${config.githubRepo}/releases?access_token=${TOKEN}"
|
httpRequest httpMode: 'POST', requestBody: data, url: "${config.githubApiUrl}/repos/${config.githubOrg}/${config.githubRepo}/releases?access_token=${TOKEN}"
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user