【问题标题】:Jenkins: push repo branch 'staging' to staging server, and branch 'production' to production server詹金斯:将回购分支“登台”推送到登台服务器,并将“生产”分支推送到生产服务器
【发布时间】:2020-04-07 09:40:06
【问题描述】:

我是 Jenkins nooooobie。是否有可能/无痛地将这两个 yaml 文件合并到一个仓库中,这样当我推送到分支“登台”时,詹金斯将其推送到登台服务器,而当我推送到分支“生产”时,詹金斯推送到生产服务器?

分期

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

【问题讨论】:

    标签: git jenkins


    【解决方案1】:

    欢迎使用 Jenkins 实现自动化! :D

    Jenkins 提供了环境变量,您可以使用这些变量来补充工作中的逻辑。在这种情况下,您可能对 GIT_BRANCH 和 GIT_LOCAL_BRANCH 环境变量感兴趣。

    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
    

    还有与不同分支机构合作的多分支机构工作方法,但这是完成您想要做的事情的一个很好的介绍性方法。

    让我们知道结果如何!

    【讨论】:

    • 要查看 Jenkins 为您的工作注入的其他环境变量,请查看您服务器上的 env-vars.html/。例如,在 localhost 上,您将转到 localhost:8080/env-vars.html。
    猜你喜欢
    • 1970-01-01
    • 2014-03-24
    • 2011-11-24
    • 1970-01-01
    • 1970-01-01
    • 2014-09-11
    • 1970-01-01
    • 2012-10-19
    • 1970-01-01
    相关资源
    最近更新 更多