Authenticate with GitHub using a token

后端 未结 10 571
广开言路
广开言路 2020-11-30 17:09

I am trying to authenticate with GitHub using a personal access token. In the help files at github, it states to use the cURL method to authenticate (https://help.github.com

10条回答
  •  孤街浪徒
    2020-11-30 17:29

    By having struggling so many hours on applying GitHub token finally it works as below:

    $ cf_export GITHUB_TOKEN=$(codefresh get context github --decrypt -o yaml | yq -y .spec.data.auth.password)

    • code follows Codefresh guidance on cloning a repo using token (freestyle}
    • test carried: sed %d%H%M on match word '-123456-whatever'
    • push back to the repo (which is private repo)
    • triggered by DockerHub webhooks

    Following is the complete code:

    version: '1.0'
    steps:
      get_git_token:
        title: Reading Github token
        image: codefresh/cli
        commands:
          - cf_export GITHUB_TOKEN=$(codefresh get context github --decrypt -o yaml | yq -y .spec.data.auth.password)
      main_clone:
        title: Updating the repo
        image: alpine/git:latest
        commands:
          - git clone https://chetabahana:$GITHUB_TOKEN@github.com/chetabahana/compose.git
          - cd compose && git remote rm origin
          - git config --global user.name "chetabahana"
          - git config --global user.email "chetabahana@gmail.com"
          - git remote add origin https://chetabahana:$GITHUB_TOKEN@github.com/chetabahana/compose.git
          - sed -i "s/-[0-9]\{1,\}-\([a-zA-Z0-9_]*\)'/-`date +%d%H%M`-whatever'/g" cloudbuild.yaml
          - git status && git add . && git commit -m "fresh commit" && git push -u origin master
    

    Output...

    On branch master 
    Changes not staged for commit: 
      (use "git add ..." to update what will be committed) 
      (use "git checkout -- ..." to discard changes in working directory) 
    
    modified:   cloudbuild.yaml 
    
    no changes added to commit (use "git add" and/or "git commit -a") 
    [master dbab20f] fresh commit 
     1 file changed, 1 insertion(+), 1 deletion(-) 
    Enumerating objects: 5, done. 
    Counting objects:  20% (1/5) ...  Counting objects: 100% (5/5), done. 
    Delta compression using up to 4 threads 
    Compressing objects:  33% (1/3) ... Writing objects: 100% (3/3), 283 bytes | 283.00 KiB/s, done. 
    Total 3 (delta 2), reused 0 (delta 0) 
    remote: Resolving deltas:   0% (0/2)  ...   (2/2), completed with 2 local objects. 
    To https://github.com/chetabahana/compose.git 
       bbb6d2f..dbab20f  master -> master 
    Branch 'master' set up to track remote branch 'master' from 'origin'. 
    Reading environment variable exporting file contents. 
    Successfully ran freestyle step: Cloning the repo 
    

提交回复
热议问题