// 所有脚本命令包含在pipeline{}中 pipeline { // 指定任务在哪个节点执行(Jenkins支持分布式) agent any // 配置全局环境,指定变量名=变量值信息 environment{ host = '172.17.1.22' } // 存放所有任务的合集 stages { // 单个任务 // stage('拉取Git代码') { // // 实现任务的具体流程 // steps { // git branch: '${BRANCH_NAME}', credentialsId: 'b4978113-0120-47f8-b809-ba6916afc6e0', url: 'http://192.168.32.253:3000/Software/android-cloud-H5.git' // } // } // 单个任务 stage('初始化构建环境') { // 实现任务的具体流程 steps { nodejs('v16'){ // sh '. /usr/local/src/.nvm/nvm.sh' // sh 'nvm install v16' // sh 'nvm use v16' sh ''' node -v npm -v npm install ''' } } } stage('构建项目') { steps { nodejs('v16'){ sh ''' if [ "${BRANCH_NAME}" == "feature/jenkinsfile" ]; then npm run build:test elif [ "${BRANCH_NAME}" == "feature/jenkinsfile2" ]; then npm run build:uat fi ''' } } } } }