Skip to content

Commit 1e776b0

Browse files
Improving security in Jenkinsfile
1 parent 4a8b9e8 commit 1e776b0

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

Jenkinsfile

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ node {
145145

146146
// get the sonatype credentials stored in the jenkins secure keychain
147147
withCredentials([
148-
usernamePassword(credentialsId: mavenCentralCredentialsId, usernameVariable: 'mavencentral_username', passwordVariable: 'mavencentral_password'),
149-
file(credentialsId: mavenCentralSignKeyFileId, variable: 'mavenCentralKeyFile'),
150-
usernamePassword(credentialsId: mavenCentralSignKeyId, passwordVariable: 'signingPassword', usernameVariable: 'signingKeyId')
148+
usernamePassword(credentialsId: mavenCentralCredentialsId, usernameVariable: 'MAVENCENTRAL_USER', passwordVariable: 'MAVENCENTRAL_PASS'),
149+
file(credentialsId: mavenCentralSignKeyFileId, variable: 'MAVENCENTRAL_KEYFILE'),
150+
usernamePassword(credentialsId: mavenCentralSignKeyId, usernameVariable: 'MAVENCENTRAL_SIGNINGKEYID', passwordVariable: 'MAVENCENTRAL_SIGNINGPASS')
151151
]) {
152152

153153
/*
@@ -159,17 +159,15 @@ node {
159159
returnStdout: true
160160
)
161161

162-
String deployGradleTasks = "--refresh-dependencies test " +
163-
"publish -Puser=${env.mavencentral_username} " +
164-
"-Ppassword=${env.mavencentral_password} " +
165-
"-Psigning.keyId=${env.signingKeyId} " +
166-
"-Psigning.password=${env.signingPassword} " +
167-
"-Psigning.secretKeyRingFile=${env.mavenCentralKeyFile} " +
162+
String deployGradleTasks = '--refresh-dependencies test ' +
163+
'publish -Puser=${MAVENCENTRAL_USER} ' +
164+
'-Ppassword=${MAVENCENTRAL_PASS} ' +
165+
'-Psigning.keyId=${MAVENCENTRAL_SIGNINGKEYID} ' +
166+
'-Psigning.password=${MAVENCENTRAL_SIGNINGPASS} ' +
167+
'-Psigning.secretKeyRingFile=${MAVENCENTRAL_KEYFILE} ' +
168168
"-PdeployVersion='$projectVersion'"
169169

170-
// see https://docs.gradle.org/6.0.1/release-notes.html "Publication of SHA256 and SHA512 checksums"
171-
def preventSHACheckSums = "-Dorg.gradle.internal.publish.checksums.insecure=true"
172-
gradle("${deployGradleTasks} $preventSHACheckSums", projectName)
170+
gradle(deployGradleTasks, projectName)
173171
}
174172

175173
if (env.BRANCH_NAME == "main") {
@@ -376,7 +374,7 @@ def gradle(String command, String relativeProjectDir) {
376374
env.JENKINS_NODE_COOKIE = 'dontKillMe' // this is necessary for the Gradle daemon to be kept alive
377375

378376
// switch directory to be able to use gradle wrapper
379-
sh(script: """set +x && cd $relativeProjectDir""" + ''' set +x; ./gradlew ''' + """$command""", returnStdout: true)
377+
sh(script: """set +x && cd $relativeProjectDir""" + ''' set +x; ./gradlew ''' + command, returnStdout: true)
380378
}
381379

382380
def determineSonarqubeGradleCmd(String sonarqubeProjectKey, String currentBranchName, String targetBranchName, String orgName, String projectName, String relativeGitDir) {

0 commit comments

Comments
 (0)