Jenkinsfile 969 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // 所有脚本命令包含在pipeline{}中
  2. pipeline {
  3. // 指定任务在哪个节点执行(Jenkins支持分布式)
  4. agent any
  5. // 配置全局环境,指定变量名=变量值信息
  6. environment{
  7. host = '172.17.1.22'
  8. }
  9. // 存放所有任务的合集
  10. stages {
  11. stage('初始化构建环境') {
  12. // 实现任务的具体流程
  13. steps {
  14. nodejs('v16') {
  15. sh '''
  16. node -v
  17. npm -v
  18. npm install
  19. '''
  20. }
  21. }
  22. }
  23. stage('构建项目') {
  24. steps {
  25. script {
  26. if ( env.BRANCH_NAME == 'master' ) {
  27. nodejs('v16') {
  28. sh 'npm run build:prod'
  29. }
  30. } else if ( env.BRANCH_NAME == 'uat' ) {
  31. nodejs('v16') {
  32. sh 'npm run build:uat'
  33. }
  34. } else {
  35. nodejs('v16') {
  36. sh 'npm run build:test'
  37. }
  38. }
  39. }
  40. }
  41. }
  42. }
  43. }