sonar-scanner \
-Dsonar.projectKey=test001 \
-Dsonar.sources=. \
-Dsonar.host.url=http://192.168.1.36:30910 \
-Dsonar.login=b73296aadf00cc684dd5483f7d4fdeacc82baa79
jenkinsfile
def POD_LABEL = "vue-pod-${UUID.randomUUID().toString()}"
def APP_DIR = "sgxt-demand-platform-frontend"
podTemplate (
label: POD_LABEL, cloud: 'kubernetes',
containers: [
containerTemplate(name: 'jnlp', image: 'jenkins/jnlp-agent-docker', args: '${computer.jnlpmac} ${computer.name}'),
containerTemplate(name: 'sonarscanner', image: 'sonarsource/sonar-scanner-cli:latest', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'nodejs', image: "node:14-alpine", ttyEnabled: true, command: 'cat',)
],
volumes: [
hostPathVolume(hostPath: '/var/run/docker.sock', mountPath:'/var/run/docker.sock'),
// hostPathVolume(hostPath: '/home/jenkins/.cache/yarn', mountPath:'/home/node/.cache/yarn'),
persistentVolumeClaim(claimName:'npm-pvc',mountPath:'/home/node/.npm',readOnly:false)
]
) {
node(POD_LABEL) {
stage('code-checkout') {
container('nodejs') {
checkout scm
}
script {
build_tag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
}
}
stage('code-sonar') {
container('sonarscanner') {
sh """
sonar-scanner \
-Dsonar.projectKey=test001 \
-Dsonar.sources=. \
-Dsonar.host.url=http://sonarqube:9000 \
-Dsonar.login=b73296aadf00cc684dd5483f7d4fdeacc82baa79
"""
}
}
stage('code-build') {
container('nodejs') {
// dir (APP_DIR) {
sh 'npm install --unsafe-perm'
sh 'npm build'
// }
}
}
stage('docker-build') {
input "继续?"
sh "docker build -t 192.168.1.207:6543/com.newpwr/sgxt-demand-platform:${build_tag} ."
}
stage('docker-push') {
withCredentials([usernamePassword(credentialsId: 'localDocker', passwordVariable: 'localDockerPassword', usernameVariable: 'localDockerUser')]) {
sh "docker login 192.168.1.207:6543 -u ${localDockerUser} -p ${localDockerPassword}"
sh "docker push 192.168.1.207:6543/com.newpwr/sgxt-demand-platform:${build_tag}"
}
}
// stage('部署') {
// }
}
}
Jenkins执行构建