mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +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))
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
String groovyObjectToJsonString(object) {
|
||||
return groovy.json.JsonOutput.toJson(object)
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
def jsonStringToGroovyObject(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))
|
||||
assertJobStatusSuccess()
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
import com.sap.piper.JsonUtils
|
||||
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.GenerateDocumentation
|
||||
@ -146,9 +148,15 @@ String addDeltaToLastRelease(config, latestTag){
|
||||
}
|
||||
|
||||
void postNewRelease(config, TOKEN, releaseBody){
|
||||
releaseBody = releaseBody.replace('"', '\\"')
|
||||
//write release information
|
||||
def data = "{\"tag_name\": \"${config.version}\",\"target_commitish\": \"master\",\"name\": \"${config.version}\",\"body\": \"${releaseBody}\",\"draft\": false,\"prerelease\": false}"
|
||||
Map messageBody = [
|
||||
tag_name: "${config.version}",
|
||||
target_commitish: 'master',
|
||||
name: "${config.version}",
|
||||
body: releaseBody,
|
||||
draft: false,
|
||||
prerelease: false
|
||||
]
|
||||
def data = new JsonUtils().groovyObjectToJsonString(messageBody)
|
||||
try {
|
||||
httpRequest httpMode: 'POST', requestBody: data, url: "${config.githubApiUrl}/repos/${config.githubOrg}/${config.githubRepo}/releases?access_token=${TOKEN}"
|
||||
} catch (e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user