Accessing another repo during build

Colby Salmon's Avatar

Colby Salmon

10 May, 2022 07:48 PM

I would like to push build artifacts to another repo during a build. After building the source code repo in the build_script section, I am attempting to clone the artifact repo in the on_success section, so that I can commit and push the artifacts. I followed the instructions in the post at this url, but I still get failed authentication:
https://help.appveyor.com/discussions/problems/555-accessing-another-repository-during-a-build

# from my appveyor.yml file:
on_success:
    - cmd: cd ../
    - git clone https://$($env:github_token):x-oauth-basic@github.com/csalmon1/BAC.git C:\projects\BAC
    - cmd: cd BAC && pwd && dir

  1. Support Staff 1 Posted by Feodor Fitsner on 11 May, 2022 03:06 AM

    Feodor Fitsner's Avatar
  2. 2 Posted by Colby Salmon on 11 May, 2022 08:47 PM

    Colby Salmon's Avatar

    I did this, but it still didn't work. Instead of giving a failed authentication error like before, it just hung (must be waiting for credentials). Also I had to change directories and init since I'm changing repos.

    environment:
        access_token:
            secure: svD9dHltYqXJZJFxS8q9W86QjQ7TLAaKLqXOjAVzwJ+v1lQ8mz8fK3dI6Te6OOGF

    on_success:
        - cmd: cd ../ && mkdir BAC && cd BAC
        - git init
        - git config --global credential.helper store
        - ps: Set-Content -Path "$HOME\.git-credentials" -Value "https://$($env:access_token):x-oauth-basic@github.com`n" -NoNewline
        - git config --global user.name "csalmon1"
        - git config --global user.email "[email blocked]"
        - git pull https://github.com/csalmon1/BAC.git
        - cmd: pwd && dir

  3. Support Staff 3 Posted by Feodor Fitsner on 11 May, 2022 09:38 PM

    Feodor Fitsner's Avatar

    Make sure you are not testing it in PR build as secure variables are not set in PR builds.

  4. 4 Posted by Colby Salmon on 11 May, 2022 10:37 PM

    Colby Salmon's Avatar

    I don't think it's a PR build. How do I check and make sure? If so, how do I change it?

    The first repo accessed for the build is a public github repo. The second repo I am trying to access to push the build artifacts is a private github repo.

  5. 5 Posted by Colby Salmon on 11 May, 2022 10:40 PM

    Colby Salmon's Avatar

    I am the owner of both repos.

  6. Support Staff 6 Posted by Feodor Fitsner on 11 May, 2022 10:54 PM

    Feodor Fitsner's Avatar

    Well, it's hard to tell what's wrong with your code - it looks OK to me. Try connecting to a build VM via RDP and experiment from there.

  7. 7 Posted by Colby Salmon on 12 May, 2022 01:17 AM

    Colby Salmon's Avatar

    It seems to work when I push back to the same repo I started with, but it doesn't work to switch and pull or clone from a different repo.

  8. Support Staff 8 Posted by Feodor Fitsner on 12 May, 2022 02:19 AM

    Feodor Fitsner's Avatar

    Perhaps you should add/update remote?

  9. 9 Posted by Colby Salmon on 12 May, 2022 11:10 PM

    Colby Salmon's Avatar

    Here is some console output that shows I have successfully configured the repo and set the remote url:

    cd ../../ && pwd && mkdir BAC && cd BAC
    /c/projects
    git init .
    Initialized empty Git repository in /c/projects/BAC/.git/
    git status
    On branch master
    No commits yet
    nothing to commit (create/copy files and use "git add" to track)
    git remote add origin https://github.com/csalmon1/BAC.git
    git remote -v
    origin https://github.com/csalmon1/BAC.git (fetch)
    origin https://github.com/csalmon1/BAC.git (push)
    git config --global credential.helper store
    Set-Content -Path "$HOME\.git-credentials" -Value "https://$($env:access_token):x-oauth-basic@github.com`n" -NoNewline
    git config --global user.name "csalmon1"
    git config --global user.email "[email blocked]"
    git fetch https://$($env:access_token):x-oauth-basic@github.com/csalmon1/BAC.git main
    remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
    remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
    fatal: Authentication failed for 'https://github.com/csalmon1/BAC.git/'
    Command exited with code 128

    When I did fetch command with no arguments, it hung and waited for credentials. When using fetch with arguments and token it fails to authenticate and tells me to use a token.

  10. Support Staff 10 Posted by Feodor Fitsner on 12 May, 2022 11:47 PM

    Feodor Fitsner's Avatar

    When you put credentials to .git-credentials I don't think you need to put them again in git fetch URL. Try just:

    git fetch https://github.com/csalmon1/BAC.git main
    

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac