1

I've a git runner setup in my gcloud instance. It is running and showing up in my runners' list. Problem occurs when my go project I'm trying to build is using a private github module.

Here are the steps I've followed:

  • exposed environment variable: GOPRIVATE=github.com/<MY_ORG>/<MY_REPO>
  • git config --global url."https://<PRIAVTE_ACCESS_TOKEN>:[email protected]/".insteadOf "https://github.com/"

But I'm still getting the following error when I'm trying to access the private module: remote: Repository not found. fatal: Authentication failed for 'https://github.com/<MY_ORG>/<MY_REPO>/'

My github action workflow file looks like this:

name: CICD
on:
  workflow_dispatch:
     inputs:
        ENV:
            description: 'ENV'
            required: true
            default: 'poc'
        DOCKER_TAG:
            description: 'docker image tag'
            required: true
            default: 'latest'
env:
  NS: ${{ vars.NS }}
  ENV: ${{ github.event.inputs.ENV }}
  DOCKER_TAG: ${{ github.event.inputs.DOCKER_TAG }}
  GOOS: ${{ vars.GOOS }}
  GOARCH: ${{ vars.GOARCH }}
  CGO_ENABLED: ${{ vars.CGO_ENABLED }}
  GKE_SA_KEY: ${{ secrets.GKE_SA_KEY }}
  GKE_CLUSTER: ${{ vars.GKE_CLUSTER }}
  GKE_ZONE : ${{ vars.GKE_ZONE }}
  DOCKER_REG: ${{ vars.DOCKER_REG }}
  PROJECT_ID:  ${{ vars.PROJECT_ID }}
  DOCKER_REPO:  ${{ vars.DOCKER_REPO }}
  APP_NAME:  ${{ vars.APP_NAME }}
  DOMAIN: ${{ vars.DOMAIN }}
  URL: ${{ vars.URL }}
  GOPRIVATE : ${{ vars.GOPRIVATE }}
  TOKEN: ${{ secrets.GITPAT }}

jobs:
  app-build:
    environment: ${{ github.event.inputs.ENV }}
    runs-on: my-self-hosted
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Configure git for private modules
        run: git config --global url."https://$TOKEN:[email protected]/".insteadOf "https://github.com/"
      - name: Build
        run: go build -o main main.go     <---- FAILING OVER HERE

Here the project I'm trying to build depends upon a private github repo.

1 Answer 1

0

I had encountered a similar issue while trying to install modules from a private repository. Following are some of my findings:

  1. Github actions generates a unique authentication token at the start of the workflow which has access only to the current repository.
  2. By default when we checkout the repository with actions/checkout, it stores the token in local github config
  3. In order to override it using ‘github config’ command, we must set ‘persist-credentials’ to false.

My github actions workflow looks like this:

 - name: checkout
   uses: actions/checkout@v3
   with:
     persist-credentials: false
 - name: npm install
   run: |
     git config —global url.”https://${{ secrets.MY_GIT_TOKEN }}@github.com/“.insteadOf ssh://[email protected]/
     npm install
 
Sign up to request clarification or add additional context in comments.

1 Comment

hey @Nadeem, this didnt help in my case. I'm still facing the same issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.