gogithubgithub-actionsdevopsjfrog-cli

How do I configure JFROG CLI and push Go artifacts to a repository using Github actions?


I am currently trying to push docker images(for deployment purposes) and build artifacts(for tracking purposes) of a Golang application and this is my current pipeline.

name: Build and Push Docker Image and Go Artifacts

on:
  push:
    branches:
      - jfrog-dev  # Your specified branch
  workflow_dispatch:  # Allows manual triggering of the workflow

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      # Step 1: Check out the code from the repository
      - name: Checkout code
        uses: actions/checkout@v2

      # Step 2: Verify JFROG_URL and USER
      - name: Verify credentials
        run: |
          echo "JFROG_URL is ${JFROG_URL}"
          echo "JFROG_USER is ${JFROG_USER}"

      # Step 3: Set up Go environment
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: '1.23'

      # Step 4: Install dependencies and build Go binary
      - name: Install dependencies and build Go binary
        run: |
          go mod tidy
          go build -o mit-sphere ./cmd/main.go

      # Step 5: Install JFrog CLI
      - name: Install JFrog CLI
        run: |
          curl -fL https://getcli.jfrog.io | sh
          sudo mv jfrog /usr/local/bin/
          echo "JFrog CLI version:"
          jfrog --version

      # Step 6: Log in to JFrog Artifactory for Docker
      - name: Log in to JFrog Artifactory for Docker
        run: |
          echo "${{ secrets.JFROG_PASSWORD }}" | docker login mani.jfrog.io -u "${{ secrets.JFROG_USER }}" --password-stdin

      # Step 7: Build and tag Docker image
      - name: Build and tag Docker image
        run: |
          docker build . -t mit-sphere:latest
          docker tag mit-sphere:latest mani.jfrog.io/mani1234-maniit/mit-sphere:latest

      # Step 8: Push Docker image to JFrog Artifactory
      - name: Push Docker image to JFrog Artifactory
        run: |
          docker push mani.jfrog.io/mani1234-maniit/mit-sphere:latest

      # Step 9: Configure JFrog CLI with username and password
      - name: Configure JFrog CLI
        run: |
          jfrog config add --url "${{ secrets.JFROG_URL }}" --user "${{ secrets.JFROG_USER }}" --password "${{ secrets.JFROG_PASSWORD }}"

      # Step 10: Deploy Go artifact to JFrog Artifactory
      - name: Deploy Go artifact to JFrog Artifactory
        run: |
          echo "Publishing Go package to JFrog Artifactory"
          jfrog gp mit-sphere-new-go 1 --server-id rt-server # 1 - stands for version number

After pushing the code and triggering the build, I keep getting the following error

Configure JFrog CLI

0s
Run jfrog config add --url "***" --user "***" --password "***"
  jfrog config add --url "***" --user "***" --password "***"
  shell: /usr/bin/bash -e {0}
  env:
    GOROOT: /opt/hostedtoolcache/go/1.23.1/x64
Error: [Error] The following error was received while trying to encrypt your password: Artifactory response: 404  
Error: Process completed with exit code 1.

I have stored the URL, User and password as GitHub secrets. Also, I have to sign-in to the console using MFA (not sure if that's a blocker here)

I am unable to get past the Configure CLI step and would like to know where exactly I am going wrong. Any help would be appreciated. Thanks!


Solution

  • There are 2 URLs in jf config add command:

    This is JFrog Artifactory URL. (example: https://mani.jfrog.io/artifactory)

    jfrog config add artifactory --artifactory-url "${{ secrets.JFROG_URL }}" --user "${{secrets.JFROG_USER }}" --password "${{ secrets.JFROG_PASSWORD }}"
    

    This is JFrog Platform URL. (example: https://mani.jfrog.io)

    jfrog config add artifactory --url "https://mani.jfrog.io" --user "${{secrets.JFROG_USER }}" --password "${{ secrets.JFROG_PASSWORD }}"
    

    Also you can set --interactive=false to be sure, even if $CI is not true.