【问题标题】:Travis CI After Success Write to a File in GitHub RepoTravis CI 成功后写入 GitHub Repo 中的文件
【发布时间】:2021-03-18 05:00:27
【问题描述】:

在我使用 Travis CI 的一个项目中,我开始编写以下脚本。

after_success:
  - MESSAGE=$(git log --format=%B -n 1 $TRAVIS_BUILD_NUMBER)
  - git clone git://${GH_REPO}
  - git config user.email "travis@travis.org"
  - git config user.name "travis"
  - git add .
  - git commit --allow-empty -m "updated README.md"
  - git push https://joesan:${GITHUB_API_KEY}@${GH_REPO} HEAD:master

所以使用上面的脚本,我想做以下事情:

  1. cd 进入包含名为 deployment-version.txt 的文件的目录(在 git clone 之后)
  2. 将 deployment-version.txt 的内容替换为我从 TRAVIS_BUILD_VERSION 变量中获得的新版本号

所以我的 deployment-version.txt 有以下 ocntent:

plant-simulator-version=512

所以有了这个成功后脚本,假设 TRAVIS_BUILD_VERSION 是 513,那么我期望

plant-simulator-version=513

作为我的新内容,我希望将此文件推送到 repo 中!任何线索我可以如何做到这一点?

【问题讨论】:

    标签: shell github continuous-integration travis-ci webhooks


    【解决方案1】:

    我设法通过编写一个只包含一行文本的新文件来做到这一点。这是现在 好的!因此,我将其发布为解决方案:

    after_success:
      - MESSAGE=$(git log --format=%B -n 1 $TRAVIS_BUILD_NUMBER)
      - git clone https://${GH_REPO}
      - cd ${PLANT_SIMULATOR_DEPLOYMENT_REPO_NAME}
      - rm deployment-version.txt    # Remove the file
      - touch deployment-version.txt # Add the file
      - echo plant-simulator.version=${TRAVIS_BUILD_NUMBER} >> deployment-version.txt
      - git config user.email "travis@travis.org"
      - git config user.name ${USER} # this email and name can be set anything you like
      - git add .
      - git commit --allow-empty -m "release version for deployment  tagged with version $TRAVIS_BUILD_NUMBER"
      - git push https://${GITHUB_API_KEY}@${GH_REPO} HEAD:master
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-03
      • 2019-10-08
      • 1970-01-01
      • 2018-11-24
      • 1970-01-01
      • 1970-01-01
      • 2016-01-19
      • 2019-05-21
      相关资源
      最近更新 更多