aexiaoliou il y a 2 ans
Parent
commit
8f571c3163
2 fichiers modifiés avec 23 ajouts et 4 suppressions
  1. 15 3
      Jenkinsfile
  2. 8 1
      README.md

+ 15 - 3
Jenkinsfile

@@ -6,7 +6,7 @@ pipeline {
     agent none
     stages {
         // 生产
-        stage('prod') {
+        stage('prod build') {
             // 自动构建项目根目录下的 Dockerfile 文件,并使用其为运行容器
             agent { dockerfile true }
             // 当分支为master的时候执行
@@ -26,7 +26,7 @@ pipeline {
             }
         }
         // 测试环境
-        stage('test') {
+        stage('test build') {
             // 使用 docker 镜像 php:7.4-cli 为运行容器
             agent { docker 'php:7.4-cli' }
             when {
@@ -37,9 +37,18 @@ pipeline {
             }
         }
         // 生产环境
-        stage('dev') {
+        stage('dev build') {
             // 在任何可用的代理上执行流水线或阶段,没有多节点的情况下其实就是直接执行shell啦。。
             agent any
+            /*
+            agent {
+                docker {
+                    image 'php:8.2-cli'
+                    lable: 'develop-server' // 在lable为xxx的节点对应docker容器运行
+                    args: ' --verbose' // 额外的docker参数
+                }
+            }
+             */
             when {
                 branch 'dev'
             }
@@ -50,6 +59,9 @@ pipeline {
         // 没有when也就是任意时候都会执行
         stage('after build') {
             agent any
+            /*
+            agent { lable: 'maybe-server' } // 在lable为xxx的节点上运行
+             */
             steps {
                 echo 'Always excecute after other stages.'
             }

+ 8 - 1
README.md

@@ -6,7 +6,8 @@ Jenkins 会根据根目录中的 [Jenkinsfile](./Jenkinsfile) 进行自动编译
 
 如果需要更多相关信息可以参考:  
 [Jenkinsfile 入门](https://www.jenkins.io/zh/doc/book/pipeline/jenkinsfile/)  
-[Jenkinsfile 参考文档](https://www.jenkins.io/zh/doc/book/pipeline/syntax/)
+[Jenkinsfile 参考文档](https://www.jenkins.io/zh/doc/book/pipeline/syntax/)  
+或者Jenkins项目左边的那个流水线语法
 
 推荐 vscode 插件:[JenkinsFile Support](https://marketplace.visualstudio.com/items?itemName=ivory-lab.jenkinsfile-support)
 
@@ -22,3 +23,9 @@ Jenkins 会根据根目录中的 [Jenkinsfile](./Jenkinsfile) 进行自动编译
 4. 添加凭据对应协作人和应有权限
 5. 在 Jenkins 中点击扫描和构建并尝试构建
 6. 测试 webhook 推送 (触发构建或者扫描日志时间改变就可以了)
+
+#### 注意事项
+
+- 如果只是要测试微调后 Jenkinsfile 可以用 Jenkins 的回放功能(点击具体构建,左边),然后再放进项目里,这样就不用一直 commit push
+- 对当前分支的 Jenkinsfile 更新不会影响到其他分支,在开发或者测试分支可以不用担心影响生产
+- 对 Jenkinsfile 的改动尽量独立为一个commit, 方便 git cherry-pick 合并单一commit到其他需要的分支