mavengithub-actionsartifactoryjfrog-cli

Jfrog CLI Maven snapshot and release deployments


In our project, we are using maven as the build tool, GitHub actions as the build agent, and Jfrog as the artifactory to deploy the jar files. We have both snapshot and release versions (identified using the "SNAPSHOT" in the version tag in pom). Currently we use the maven deploy plugin to deploy the built artifacts to Jfrog and the details of the repository are configured in the maven settings.xml file using the following tags in the maven profile:

artifactory repo configuration in maven settings file

When running maven deploy, the deploy plugin builds the project and deploys it to the artifactory and respective repository based on the artifact's version (whether "SNAPSHOT" is present or not). After going through a few documents and blogs such as the following one:

https://jfrog.com/blog/dont-let-maven-deploy-plugin-trip-you

we thought it was better to use the jfrog artifactory plugin to achieve this so that we can capture build info and other relevant parameters. Since we are using GitHub actions, I could not find an artifactory plugin that is used for GitHub actions (found one for Jenkins and a few others but not for GitHub actions), I also don't want to add the plugin to my pom file and configure the repository details there as it would tie the repository details in pom. Also, I would like to separate the deploy logic from pom and move it to a CI server, so that these details can be hidden from the developers (the maven deploy plugin does this somewhat as all the artifactory config happens in the maven settings file)

The artifactory plugin can be configured in pom as follows:

artifactory plugin configuration from Jfrog blog

referenced from https://www.jfrog.com/confluence/display/JFROG/Maven+Artifactory+Plugin

Then I found that we can use Jfrog CLI in GitHub actions to deploy the artifacts, but I could not find how I can configure the CLI to use both snapshot and release repositories so that I do not have to manually decide where to upload them by using the repo name. Can anybody guide me on how to achieve this in CLI?

I have referred to the following links from GitHub as well as jfrog:


Solution

  • So, I have finally managed to figure out how this can be done using github actions.

    In my actions.yml file, I have added a new step which makes use of "jfrog/setup-jfrog-cli" action from the github actions marketplace, the link to this is as follows. It shows you how to configure the action.

    https://github.com/marketplace/actions/setup-jfrog-cli

    I have configured the artifactory platform url as well as the username and access token in this action.

    A new action was created which would build my code using the "jf maven" goal. Before you can make use of maven using jfrog CLI, it needs to be configured using the "jf mvn-config" command, it is here that you can specify which are the release and snapshot repositories that you want to make use of. The following is the code snippet that I have used for the same. Please note that these are steps within the github actions pipeline job and not the complete build yml file'

    - name: Setup jfrog
            uses: jfrog/setup-jfrog-cli@v3
            with:
              version: latest
            env:
              JF_URL: "https://artifactory.com"  #be mindful not to add the path /artifactory here as it will cause authentication issue
              JF_USER: ${{ secrets.ARTIFACT_USER_ID }}
              JF_ACCESS_TOKEN: ${{ secrets.ARTIFACT_TOKEN }} # You have an option of giving password as well
    
    - name: maven build
            run: |
                  jf mvn-config --repo-deploy-releases=${ARTIFACTORY_RELEASE} --repo-deploy-snapshots=${ARTIFACTORY_SNAPSHOT} # mention the names of your release and snapshot repos within the jfrog artifacory
                  jf mvn deploy
                  jf rt bp # (optional, deploy build info, use --dry-run flag to see the build info in console without committing it)
    

    There are many other optional parameters which you can use to enrich and configure the build, it can be found in the following links

    https://www.jfrog.com/confluence/display/CLI/CLI+for+JFrog+Artifactory#CLIforJFrogArtifactory-RunningMavenBuilds https://www.jfrog.com/confluence/display/JFROG/QuickStart+Guide%3A+Maven+and+Gradle https://www.jfrog.com/confluence/display/CLI/CLI+for+JFrog+Artifactory#CLIforJFrogArtifactory-BuildIntegration