你是正確的,你可以在此更好地管理Jenkins Pipeline
你可以做的是:
1)檢出來自Dev分支的代碼,並把它放在一個目錄中的工作空間。
2)從該目錄編譯和部署。
3)添加一個手動步驟以批准從主分支部署。
4)重複步驟1和2。
樣品代碼看起來是這樣的:
node {
// Get code from git repo
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: "origin/dev"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'test-dev-dir']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '<jenkins-github-credential-id>', url: 'https://github.com/test']]]
dir('test-dir') {
// Do your stuff
}
// stage concurrency: 1, name: 'approve'
// input id: 'master-deploy', message: 'Deploy from master?', ok: 'Deploy'
// Get code from git repo
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: "origin/master"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'test-master-dir']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '<jenkins-github-credential-id>', url: 'https://github.com/test']]]
dir('test-master-dir') {
// Preferbably create a tag for future hotfix maybe?
// Do your stuff
}
}
感謝和Manish。你如何將Dev代碼更改推回到prod repo? –
我相信這是一個合併過程,所以我建議遵循當前手動合併過程,因爲可能存在潛在的衝突,需要手動解決。這就是爲什麼我添加了手動審批流程,以便一旦有人將其合併,他們可以批准部署。 –