diff --git a/Jenkinsfile b/Jenkinsfile index 7a3501bb..e108176e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,7 +17,7 @@ pipeline { NAMESPACE = 'library' GITLAB_ACCOUNT = 'admin1' APP_NAME = 'devops-sample-s2i' - SONAR_TOKEN_ID= 'sonar-token' + SONAR_CREDENTIAL_ID= 'sonar-token' } stages { @@ -38,8 +38,10 @@ pipeline { stage('sonarqube analysis') { steps { container ('maven') { - withSonarQubeEnv('sonar') { - sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN_ID" + withCredentials([string(credentialsId: "$SONAR_CREDENTIAL_ID", variable: 'SONAR_TOKEN')]) { + withSonarQubeEnv('sonar') { + sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN" + } } timeout(time: 1, unit: 'HOURS') { waitForQualityGate abortPipeline: true diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 1b49cae4..d13d093a 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -17,7 +17,7 @@ pipeline { NAMESPACE = 'docker_username' GITHUB_ACCOUNT = 'kubesphere' APP_NAME = 'devops-sample-s2i' - SONAR_TOKEN_ID= 'sonar-token' + SONAR_CREDENTIAL_ID= 'sonar-token' } stages { @@ -38,8 +38,10 @@ pipeline { stage('sonarqube analysis') { steps { container ('maven') { - withSonarQubeEnv('sonar') { - sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN_ID" + withCredentials([string(credentialsId: "$SONAR_CREDENTIAL_ID", variable: 'SONAR_TOKEN')]) { + withSonarQubeEnv('sonar') { + sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN" + } } timeout(time: 1, unit: 'HOURS') { waitForQualityGate abortPipeline: true diff --git a/src/main/java/io/kubesphere/devops/HelloWorldController.java b/src/main/java/io/kubesphere/devops/HelloWorldController.java index 9534dc9d..ade8c5bf 100644 --- a/src/main/java/io/kubesphere/devops/HelloWorldController.java +++ b/src/main/java/io/kubesphere/devops/HelloWorldController.java @@ -16,4 +16,4 @@ public class HelloWorldController { public String sayHello() { return "Hello,World!"; } -} \ No newline at end of file +}