image.png
    image.png

    image.png
    image.png
    image.png

    1. sonar-scanner \
    2. -Dsonar.projectKey=test001 \
    3. -Dsonar.sources=. \
    4. -Dsonar.host.url=http://192.168.1.36:30910 \
    5. -Dsonar.login=b73296aadf00cc684dd5483f7d4fdeacc82baa79

    jenkinsfile

    1. def POD_LABEL = "vue-pod-${UUID.randomUUID().toString()}"
    2. def APP_DIR = "sgxt-demand-platform-frontend"
    3. podTemplate (
    4. label: POD_LABEL, cloud: 'kubernetes',
    5. containers: [
    6. containerTemplate(name: 'jnlp', image: 'jenkins/jnlp-agent-docker', args: '${computer.jnlpmac} ${computer.name}'),
    7. containerTemplate(name: 'sonarscanner', image: 'sonarsource/sonar-scanner-cli:latest', command: 'cat', ttyEnabled: true),
    8. containerTemplate(name: 'nodejs', image: "node:14-alpine", ttyEnabled: true, command: 'cat',)
    9. ],
    10. volumes: [
    11. hostPathVolume(hostPath: '/var/run/docker.sock', mountPath:'/var/run/docker.sock'),
    12. // hostPathVolume(hostPath: '/home/jenkins/.cache/yarn', mountPath:'/home/node/.cache/yarn'),
    13. persistentVolumeClaim(claimName:'npm-pvc',mountPath:'/home/node/.npm',readOnly:false)
    14. ]
    15. ) {
    16. node(POD_LABEL) {
    17. stage('code-checkout') {
    18. container('nodejs') {
    19. checkout scm
    20. }
    21. script {
    22. build_tag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
    23. }
    24. }
    25. stage('code-sonar') {
    26. container('sonarscanner') {
    27. sh """
    28. sonar-scanner \
    29. -Dsonar.projectKey=test001 \
    30. -Dsonar.sources=. \
    31. -Dsonar.host.url=http://sonarqube:9000 \
    32. -Dsonar.login=b73296aadf00cc684dd5483f7d4fdeacc82baa79
    33. """
    34. }
    35. }
    36. stage('code-build') {
    37. container('nodejs') {
    38. // dir (APP_DIR) {
    39. sh 'npm install --unsafe-perm'
    40. sh 'npm build'
    41. // }
    42. }
    43. }
    44. stage('docker-build') {
    45. input "继续?"
    46. sh "docker build -t 192.168.1.207:6543/com.newpwr/sgxt-demand-platform:${build_tag} ."
    47. }
    48. stage('docker-push') {
    49. withCredentials([usernamePassword(credentialsId: 'localDocker', passwordVariable: 'localDockerPassword', usernameVariable: 'localDockerUser')]) {
    50. sh "docker login 192.168.1.207:6543 -u ${localDockerUser} -p ${localDockerPassword}"
    51. sh "docker push 192.168.1.207:6543/com.newpwr/sgxt-demand-platform:${build_tag}"
    52. }
    53. }
    54. // stage('部署') {
    55. // }
    56. }
    57. }

    Jenkins执行构建
    image.png
    image.png
    image.png