我是詹金斯的傻子。是否有可能/不费力地将这两个Yaml文件组合在一起并放入一个回购中,以便当我推送到分支“登台”时,詹金斯将其推送到登台服务器,而当我推送到分支“生产”时,詹金斯将其推送到生产服务器? >
STAGING
jenkins:
project: "Docker Slot StageSlot1 (WestUS)"
certbot_url: "https://cert.bots.company.com/"
certbot_token: "company-certbot-token"
domain_file: domain.yaml
docker:
ucp: "tcp://ucp-companydocker.westus.cloudapp.azure.com:443"
dtr: dtr-companydocker.westus.cloudapp.azure.com
ucpid: companyucpdockerwestus
dtrid: jenkinscompanydtrwestus
stackname: COMPANY-SS1-Staging
dockerfile: Dockerfile.build.tmpl
compose: docker-compose-ss1
dtrtag: "/company/stagslot"
ext_port: 8310
ext_https_port: 8311
build_cmd: ""
label: "/Staging/COMPANY/SS1"
cnt: 2
dir_rand: PM25SS1
siteurl: "http://company-ss1-stage.trafficmanager.net"
build_cache: false
slack:
channel: "#webops"
log_errors: false
git:
gitid: company-ss1-id
giturl: "git@github.com:company/company-SS1.git"
gitbranch: staging
生产
jenkins:
project: "Docker Slot ProdSlot1"
certbot_url: "https://cert.bots.company.com/"
certbot_token: "company-certbot-token"
domain_file: domain.yaml
docker:
dockerfile: Dockerfile.build.tmpl
build_cmd: ""
cnt: 4
dir_rand: PM25MS1
siteurl: "http://company-prodslot1.us-west1.gce.companyp.cloud"
build_cache: false
k8s:
gcpid: 'gcp-web-platform'
namespace: 'production'
site: 'ms-01'
env: 'prod'
clusters:
- name: 'gke-web-1'
region: 'us-west1'
slothost: 'company-ms01.us-west1.gce.companyp.cloud'
- name: 'gke-web-2'
region: 'us-central1'
slothost: 'company-ms01.us-central1.gce.companyp.cloud'
slack:
channel: "#webops"
log_errors: false
git:
gitid: company-prodslot1-id
giturl: "git@github.com:company/company-prodslot1.git"
gitbranch: production
答案 0 :(得分:1)
欢迎使用Jenkins实现自动化! :D
Jenkins提供了环境变量,您可以使用它们来补充作业中的逻辑。在这种情况下,您可能会对GIT_BRANCH
和GIT_LOCAL_BRANCH
env变量感兴趣。
GIT_BRANCH - The remote branch name, if any.
GIT_LOCAL_BRANCH - The local branch name being checked out, if applicable.
因此,在工作中,您可以执行以下操作(遵循bash启发式伪代码!!):
case ${GIT_BRANCH} in
staging) push_to_staging_sever;;
production) push_to_production_sever;;
esac
也有用于与不同分支机构合作的多分支工作方法,但这是一种很好的介绍性方法,可以完成您要尝试做的事情。
让我们知道它是如何工作的!