How to push a commit to Github from a CircleCI build using a personal access token

后端 未结 3 1441
旧巷少年郎
旧巷少年郎 2021-02-07 09:32

When executing a build for git repository giantswarm/docs-content in CircleCI, I\'d like to push a commit to another repository giantswarm/docs.

<
3条回答
  •  野的像风
    2021-02-07 10:13

    Thanks to the hint by Ali Amin I now have this working solution:

    version: 2
    jobs:
      build:
        machine: true
        steps:
          - run:
              name: Clone docs
              working_directory: ~/workdir
              command: |
                git clone --depth 1 https://${DOCS_GITHUB_TOKEN}@github.com/giantswarm/docs.git
          - deploy:
              name: Trigger docs deployment
              working_directory: ~/workdir/docs
              command: |
                git config credential.helper 'cache --timeout=120'
                git config user.email ""
                git config user.name "Deployment Bot"
                git commit --allow-empty -m "Trigger deployment"
                # Push quietly to prevent showing the token in log
                git push -q https://${DOCS_GITHUB_TOKEN}@github.com/giantswarm/docs.git master
    

    Some notes:

    • The git clone is first.
    • All subsequent git commands have to be executed in the clone directory. working_directory simplifies this a great deal.
    • The token DOCS_GITHUB_TOKEN is a personal access token with repo scope for the target repository.

提交回复
热议问题