https://note.youdao.com/ynoteshare/index.html?id=5e179224c5a950a37722fae229521696&type=note&_time=1679042043356

  • 分支源: 选择对应git项目
  • 行为:
    发现分支选择 根据名称过滤(支持正则表达式)
    input框输入(master|develop|release.|feature.|bugfix.*)
  • 扫描多分支流水线触发器(安装 Multibranch Scan Webhook Trigger插件)
    勾选 Scan by webhook
    填入Trigger token(自定义)
扫描 多分支流水线 触发器 1分钟

pipeline {
    agent any
    stages {
        stage('当前分支') {
            steps {
                echo "current branch: $BRANCH_NAME"
            }
        }

        stage('develop部署') {
            when {
                branch 'develop'
            }
            steps {
                echo 'step 1: 拉取代码'
                git branch: 'dev', credentialsId: 'e9191bdd', url: 'ssh://git@gitlab.schoo'
                echo 'step 2: 压缩打包'
                sh 'tar -zcf demo.tar.gz .[!.]* * --exclude=.git --exclude=.github'
                echo 'step 3: 执行shell远程部署'
                sshPublisher(publishers: [])
            }
        }

        stage('release部署') {
            when {
                branch 'release'
            }
            steps {
                echo 'step 1: 拉取代码'
                git branch: 'release', credentialsId: 'e9191bdd-', url: 'ssh://git'
                echo 'step 2: 压缩打包'
                sh 'tar -zcf demo.tar.gz .[!.]* * --exclude=.git --exclude=.github'
                echo 'step 3: 执行shell远程部署'
                sshPublisher(publishers: [...])
            }
        }

        stage('master部署') {
            when {
                branch 'master'
            }
            steps {
                echo 'step 1: 拉取代码'
                git branch: 'master', credentialsId: 'b466e4ddfc27', url: 'ssh://git'
                echo 'step 2: 压缩打包'
                sh 'tar -zcf demo.tar.gz .[!.]* * --exclude=.git --exclude=.github'
                echo 'step 3: 执行shell远程部署'
                sshPublisher(publishers: [...])
            }
        }
    }
}