Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git failed: exit status 128 #35

Closed
TG-KK opened this issue Sep 19, 2018 · 13 comments
Closed

git failed: exit status 128 #35

TG-KK opened this issue Sep 19, 2018 · 13 comments

Comments

@TG-KK
Copy link

TG-KK commented Sep 19, 2018

Till now I was using jtarchie's pr resource, as that image has git username param. Whenever I used telia-oss version, I got the below error in the resource check itself:

Initialized empty Git repository in /tmp/build/get/.git/
2018/08/27 22:00:34 get failed: exit status 128

SO says it could be due to missing username and email, and indeed the error disappeared when I used jtarchie's resource along with username param.

But now, since he's retiring his resource(#34), I think we need to add username param into this resource as well.

@itsdalmo
Copy link
Contributor

Hey! Could you include a trimmed down version of your pipeline definition, or just the part that shows your source configuration for the resource?

@jtarchie
Copy link

jtarchie commented Sep 19, 2018

@itsdalmo, they are referring to the fact that basic auth can be used with an https checkout, rather than a git+ssh checkout. This is something that some Github Enterprise setups do.

@TG-KK
Copy link
Author

TG-KK commented Sep 19, 2018

@itsdalmo Sure, here it is:

---
  resource_types:
    - name:                      pull-request
      type:                      docker-image
      source:
        repository:              jtarchie/pr
        tag:                     latest
        registry_mirror:         https://docker.mycompany.com

  resources:
    - name:                      pr-code
      type:                      pull-request
      source:
        repo:                    my_org/code_repo
        access_token:            ((ci.personal_access_token))
        uri:                     https://github.mycompany.com/my_org/code_repo
        base:                    develop
        private_key:             ((ci.private_key))
        api_endpoint:            https://github.mycompany.com/api/v3/
        disable_forks:           false
        only_mergeable:          true
        require_review_approval: false
        username:                ((ci.name))
        password:                ((ci.password))
        ci_skip:                 true
        skip_ssl_verification:   true
      webhook_token:             ((token.webhook))

  jobs:
    - name:                      unit-tests
      max_in_flight:             3
      build_logs_to_retain:      5
      disable_manual_trigger:    true
      plan:
      - get:                     pr-code
        trigger:                 true
        params:
          version:               every
          fetch_merge:           true
      - put:                     pr-code
        params:
          path:                  pr-code
          status:                pending
          context:               unit-tests
      - task:                    unit-test
        file:                    pr-code/ci/tasks/unit_test.yml
        input_mapping: {code_src: pr-code}
        params:
          ci.private_key:        ((ci.private_key))
          GITHUB_TOKEN:          ((ci.personal_access_token))
          SLACK_WEBHOOK_URL:     ((token.slack))
        on_success:
            put:                 pr-code
            params:
              path:              pr-code
              status:            success
              context:           unit-tests
        on_failure:
            put:                 pr-code
            params:
              path:              pr-code
              status:            failure
              context:           unit-tests

@jtarchie I think you're correct.

@itsdalmo
Copy link
Contributor

Thanks @jtarchie! The resource should already use https for the pull and fetch, and includes the access_token from the source configuration as described here so that we essentially end up with git pull https://x-access-token:<access_token>@<repo-uri> (and the URI is not specified by the user but retrieved from the Github API). Since the access_token is used to clone the repository it also needs read access for repository contents, which should make the username and password unnecessary.

@TG-KK - Did your source configuration look a little something like the example below when using teliaoss/github-pr-resource?

    resource_types:
    - name:                      pull-request
      type:                      docker-image
      source:
        repository:              teliaoss/github-pr-resource
        tag:                     latest

  resources:
    - name:                      pr-code
      type:                      pull-request
      source:
        repository:              my_org/code_repo
        access_token:            ((ci.personal_access_token))
        v3_endpoint:             https://github.mycompany.com/api/v3/
        v4_endpoint:             https://github.mycompany.com/api/v4/ # Just examples
        disable_ci_skip:         false      
      webhook_token:             ((token.webhook))

(Note: This resource is not a drop-in replacement for the github-pullrequest-resource)

@TG-KK
Copy link
Author

TG-KK commented Sep 24, 2018

@itsdalmo Sorry for delay! Here is the older config, where I get git exit 128 error:

---
  resource_types:
    - name:                   pull-request
      type:                   docker-image
      source:
        repository:           teliaoss/github-pr-resource
        tag:                  latest
        registry_mirror:      https://docker.artifactory.mycompany.com


  resources:
    - name:                   pr-code
      type:                   pull-request
      source:
        repository:           my_org/code_repo
        access_token:         ((ci.personal_access_token))
        v3_endpoint:          https://github.mycompany.com/api/v3/
        v4_endpoint:          https://github.mycompany.com/api/graphql
      webhook_token:          ((token.webhook))


  jobs:
    - name:                   unit-tests
      max_in_flight:          3
      build_logs_to_retain:   5
      disable_manual_trigger: false
      plan:
      - get:                  pr-code
        trigger:              true
        params:
          version:            every
          fetch_merge:        true
      - put:                  pr-code
        params:
          path:               pr-code
          status:             pending
          context:            unit-tests
      - task:                 unit-test
        file:                 pr-code/ci/tasks/unit_test.yml
        input_mapping: {code_src: pr-code}
        params:
          ci.private_key:     ((ci.private_key))
          GITHUB_TOKEN:       ((ci.personal_access_token))
          SLACK_WEBHOOK_URL:  ((token.slack))
        on_success:
            put:              pr-code
            params:
              path:           pr-code
              status:         success
              context:        unit-tests
        on_failure:
            put:              pr-code
            params:
              path:           pr-code
              status:         failure
              context:        unit-tests

PR check goes fine:
image

But, in the get step it fails:
image

@itsdalmo
Copy link
Contributor

itsdalmo commented Sep 25, 2018

Thanks @TG-KK!

A successful pull should look something like this:

Initialized empty Git repository in /tmp/build/get/.git/
Switched to a new branch 'ead8f4221d0ae75ded91629b4f81d1e1081595f9'
Updating ead8f42..10e1068
Fast-forward

In your case you successfully initialise git, but fail before switching branch, which means the error has to occur somewhere in this area of the code: https://github.com/telia-oss/github-pr-resource/blob/master/in.go#L27-L38

Out of Pull, Fetch and RevParse only RevParse does not add any contextual information to the error. I.e., if the error had originated from Pull or Fetch the error should have read e.g:
get failed: pull failed: exit status 128.

So it seems like RevParse is failing us here, although its simply supposed to get the BaseRefName after fetching the PullRequest object from the GraphQL API and run git rev-parse --verify master (if e.g. master was the base ref of the PR). The only thing I can think of that would choke it up is that the base ref listed in the pull request object can be a deleted reference?

If that is not the case, then I'll need to get some more information - perhaps you could run the following (which should be equivalent to what the resource would do) and see what happens?

docker run -it --rm --entrypoint /bin/sh teliaoss/github-pr-resource:latest -c "
mkdir source && cd source
git init
git config user.name concourse-ci
git config user.email concourse@local
git pull https://x-access-token:<TOKEN>@github.mycompany.com/my_org/code_repo.git 
ls -la
git rev-parse --verify master
echo exit code: $?
"

And change master to the name of the base for the PR you are testing.

@itsdalmo
Copy link
Contributor

@TG-KK - I've added more context to the rev-parse error in #40, which has now been merged and should be available under the dev tag on Docker Hub. So if you re-run your pipeline with the following changes:

      source:
        repository:           teliaoss/github-pr-resource
        tag:                  dev <--- INSTEAD OF LATEST
        registry_mirror:      https://docker.artifactory.mycompany.com

We should hopefully get a better idea about what is going on 😆

@TG-KK
Copy link
Author

TG-KK commented Sep 25, 2018

Ok, here is the output for docker run:
Our base branch is currently develop, it used to be master, but at somepoint it changed.

+ mkdir source
+ cd source
+ git init
Initialized empty Git repository in /git/source/.git/
+ git config user.name my_username
+ git config user.email my_email
+ git pull https://x-access-token:[email protected]/my_org/code_repo.git
remote: Counting objects: 3705, done.
remote: Total 3705 (delta 0), reused 0 (delta 0), pack-reused 3705
Receiving objects: 100% (3705/3705), 2.98 MiB | 402.00 KiB/s, done.
Resolving deltas: 100% (2339/2339), done.
From https://github.mycompany.com/my_org/code_repo
 * branch            HEAD       -> FETCH_HEAD
+ ls -la
total 172
<list of files redacted>
+ git rev-parse --verify develop
fatal: Needed a single revision
+ echo exit code: 2
exit code: 2
bash-4.4$

Let me give a try on running with dev tag image.

@TG-KK
Copy link
Author

TG-KK commented Sep 25, 2018

Same error using the dev tag:

image

@itsdalmo
Copy link
Contributor

Thanks @TG-KK!

I believe #41 has this fixed, will get it merged tomorrow and release a new dev tag for you to test against 🙌

@itsdalmo
Copy link
Contributor

itsdalmo commented Sep 26, 2018

@TG-KK - The PR has been merged now and the changes are live under the dev tag. Please test and report back if it resolves your issue - I'll do a proper release when we are sure its fixed 👍

@TG-KK
Copy link
Author

TG-KK commented Sep 26, 2018

@itsdalmo Thank you so much, PR now works when using the dev tag!

@itsdalmo
Copy link
Contributor

itsdalmo commented Sep 26, 2018

Great to hear! I'll close the issue now and make a new release 👍
edit: Released in v0.6.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants