How to connect JFrog CLI in GitHub Actions:

ARTIFACTORY: How to connect and publish simple build using GitHub Action with JFrog CLI

AuthorFullName__c
Nathan Amiel
articleNumber
000005678
ft:sourceType
Salesforce
FirstPublishedDate
2023-04-13T10:51:18Z
lastModifiedDate
2024-06-23
VersionNumber
3
First, we need to set up a GitHub repository and connect it to Artifactory. This can be done by setting up an OIDC integration & mapping of the GitHub repository into an Artifactory entity, or by creating a personal access token on Artifactory and adding it as a secret in the GitHub repository.
For setting up OIDC, please refer to Configure an OIDC Integration JFrog documentation
For a better understanding of the JFrog Cli setup action, please read and refer to Setup JFrog CLI documentation
For additional information on GitHub secrets, please refer to GitHub official documentation.
Now you can use the jfrog/setup-jfrog-cli action to set up the JFrog CLI with the Artifactory URL and access token.
name: Push Build to Artifactory


on: [push]


jobs:
 build:
   runs-on: ubuntu-latest
  
   steps:
   # This action checks out the code from the repository
   - name: Checkout Code
     uses: actions/checkout@v2


   # This action sets up the JFrog CLI with Artifactory URL and    a predefined Artifactory oidc integration name
   - uses: jfrog/setup-jfrog-cli@v4
     with:
          oidc-provider-name: <oidc integration name>
     env:
       JF_URL: ${{ vars.ARTIFACTORY_URL }}
       JF_PROJECT: ${{ vars.JF_PROJECT }} # optional variable

      
   # This action sets up the JFrog CLI with the Artifactory URL and access token     
   - uses: jfrog/setup-jfrog-cli@v4
     env:
       JF_URL: ${{ vars.ARTIFACTORY_URL }}
       JF_ACCESS_TOKEN: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }} 



   # This command adds a new server configuration to the JFrog CLI, as an alternative for using the setup-jfrog-cli action    
   - run: |
       export SERVER_ID="test"
       jf c add $SERVER_ID --url=$URL --access-token=$ACCESS_TOKEN --interactive=false


   # This action creates a new test file and uploads it to Artifactory, if build_name and build_number are omitted GitHub run default are used     
   - name: Push Build to Artifactory
     run: |
       echo "test file " > test.txt
       export BUILD_NAME="my-build"
       export BUILD_MODULE="my-module"
       export BUILD_NUMBER="1"


       export PATH_TO_DIRECTORY="name/version/dates"
      
       jf rt upload "test.txt" example-repo-local/$PATH_TO_DIRECTORY --build-name $BUILD_NAME --build-number $BUILD_NUMBER --module $BUILD_MODULE


   # This action publishes the build information to Artifactory and deletes older builds
   - name: Build to Artifactory
     run: |
       jf rt build-publish $BUILD_NAME $BUILD_NUMBER
     
       jf rt bdi c --max-builds=1

In this example, we have defined a workflow that is triggered when a push event occurs. The workflow contains a single job named build, which runs on an Ubuntu latest virtual machine.