Jenkinsfile-ui 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // 所有的脚本命令都放在pipeline中
  2. pipeline{
  3. // 指定任务的构建在哪个集群节点中执行,any指任意一个
  4. agent any
  5. // 声明全局变量,方便后面使用
  6. environment {
  7. harbor_user = 'admin'
  8. harbor_passwd = 'Zq0034bgns.'
  9. harbor_address = '192.168.0.5:9080'
  10. harbor_repo = 'repo'
  11. }
  12. stages {
  13. stage('拉取git仓库代码') {
  14. steps {
  15. checkout scmGit(branches: [[name: 'origin/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'ef3dc13b-dfb3-4c7a-932d-af43fd8e0fa0', url: 'http://192.168.0.5:13000/Ruoyi/RuoYi-UI.git']])
  16. }
  17. }
  18. stage('通过node构建项目') {
  19. steps {
  20. nodejs('nodejs24.12.0') {
  21. sh '''
  22. npm install --registry=https://registry.npmmirror.com
  23. npm run build:prod
  24. '''
  25. }
  26. }
  27. }
  28. stage('通过SonerQube做代码质量检测') {
  29. steps {
  30. sh '/var/jenkins_home/sonar-scanner/bin/sonar-scanner -Dsonar.sources=. -Dsonar.projectname=${JOB_NAME} -Dsonar.projectKey=${JOB_NAME} -Dsonar.token=squ_b5fe8ff602839ce1b3374e2716a1741e62777e79'
  31. }
  32. }
  33. stage('通过Docker制作自定义镜像') {
  34. steps {
  35. sh '''docker build -t ${JOB_NAME}:latest ./docker/'''
  36. }
  37. }
  38. stage('将自定义镜像推送到Harbor') {
  39. steps {
  40. sh '''docker login -u ${harbor_user} -p ${harbor_passwd} ${harbor_address}
  41. docker tag ${JOB_NAME}:latest ${harbor_address}/${harbor_repo}/${JOB_NAME}:latest
  42. docker push ${harbor_address}/${harbor_repo}/${JOB_NAME}:latest'''
  43. }
  44. }
  45. stage('将yaml文件传到k8smaster服务器') {
  46. steps {
  47. sshPublisher(publishers: [sshPublisherDesc(configName: '应用服务器', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'ruoyi-ui-deploy.yaml')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
  48. }
  49. }
  50. stage('远程执行k8s-master的kubectl命令') {
  51. steps {
  52. sh '''ssh root@192.168.0.3 kubectl apply -f ruoyi-ui-deploy.yaml'''
  53. }
  54. }
  55. }
  56. }