Reputation: 7153
I'm a Jenkins nooooobie. Is it possible / painless combine these two yaml files and place in one repo such that when I push to branch 'staging' Jenkins pushes it to the staging server and when I push to branch 'production' Jenkins pushes to the production server?
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: "[email protected]:company/company-SS1.git"
gitbranch: staging
PRODUCTION
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: "[email protected]:company/company-prodslot1.git"
gitbranch: production
Upvotes: 0
Views: 55
Reputation: 1553
Welcome to automating with Jenkins! :D
Jenkins provides environment variables that you can use to supplement the logic in your jobs. In this case, you might be interested in the GIT_BRANCH
and GIT_LOCAL_BRANCH
env variables.
GIT_BRANCH - The remote branch name, if any.
GIT_LOCAL_BRANCH - The local branch name being checked out, if applicable.
So in your job, you can do something like (bash inspired pseudo code follows!!!):
case ${GIT_BRANCH} in
staging) push_to_staging_sever;;
production) push_to_production_sever;;
esac
There are also multi-branch job approaches to working with different branches, but this is a good introductory approach to accomplish what you're trying to do.
Let us know how it works out!
Upvotes: 1