Jenkinsfile 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // 所有脚本命令包含在pipeline{}中
  2. pipeline {
  3. // 指定任务在哪个节点执行(Jenkins支持分布式)
  4. agent any
  5. // 配置全局环境,指定变量名=变量值信息
  6. environment{
  7. host = '172.17.1.22'
  8. }
  9. triggers {
  10. GenericTrigger(
  11. genericVariables: [
  12. [key: 'ref', value: '$.ref']
  13. ],
  14. causeString: 'Triggered on $ref',
  15. token: 'jenkins',
  16. tokenCredentialId: '',
  17. silentResponse: false,
  18. printPostContent: true,
  19. printContributedVariables: true,
  20. regexpFilterExpression: 'refs/heads/' + env.BRANCH_NAME,
  21. regexpFilterText: '$ref'
  22. )
  23. }
  24. // 存放所有任务的合集
  25. stages {
  26. // 实现任务的具体流程
  27. stage('初始化构建环境') {
  28. steps {
  29. nodejs('v16') {
  30. sh '''
  31. node -v
  32. npm -v
  33. npm install
  34. '''
  35. }
  36. }
  37. }
  38. stage('构建项目') {
  39. steps {
  40. script {
  41. if ( env.TAG_NAME ) {
  42. nodejs('v16') {
  43. sh 'npm run build:prod'
  44. }
  45. } else if ( env.BRANCH_NAME == 'master' ) {
  46. nodejs('v16') {
  47. sh 'npm run build:prod'
  48. }
  49. } else if ( env.BRANCH_NAME == 'uat' ) {
  50. nodejs('v16') {
  51. sh 'npm run build:uat'
  52. }
  53. } else {
  54. nodejs('v16') {
  55. sh 'npm run build:test'
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }
  62. }