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 using the following tags in the maven profile:
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 (has "SNAPSHOT" 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 all among others. 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:
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:
https://github.com/marketplace/actions/setup-jfrog-cli
https://github.com/marketplace/actions/jfrog-cli-for-artifactory
https://jfrog.com/blog/jfrog-cli-github-actions-hero
https://jfrog.com/blog/publishing-binaries-using-the-jfrog-cli
https://jfrog.com/blog/using-the-jfrog-cli-with-github-actions
https://www.jfrog.com/confluence/display/CLI/JFrog+CLI
SO, I have finally managed to figure out how this can be done using github actions.
Im 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 completed 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
Related
I am currently working on automating a Java Build and Deployment task where I am using GitHub Actions to perform the Build and Deployment. I am working on snapshots build and the artifact is pushed to JFrog Package Manager and the artifact name looks like jd-bulk-messenger-1.18.0-RC1-SNAPSHOT.war but when it gets pushed to my JFrog Snapshot Repository the same artifact seems to be uploaded with some timestamp as suffix like jd-bulk-messenger-1.18.0-RC1-20220715.124710-5.war.
How to ensure that I deploy the last recent snapshot artifacts on my target servers? I need some way to retrieve the last recent artifact name from JFrog Package Manager.
Note:
I know that we can use upload-artifact action to Archive the Artifact and can be used at later jobs with download-artifact action to perform the Deployment.
name: Archive Build Artifacts
uses: actions/upload-artifact#v3
But the Artifact size is of around 180 MB, so archiving the artifact of every build seems like not a good idea.
JFrog CLI offers extended support for complex download patterns. I think, following should help you -
First setup JFrog CLI in Github Action, check this link for installation.
Once CLI is configured to be used, you use following command to always download the latest snapshot.
jfrog rt dl --flat --limit=1 --sort-by=created --sort-order=desc --url=<ARTIFACTORY_URL> --user=<ARTIFACTORY_USER> --password=<ARTIFACTORY_PW> "<RELATIVE_PATH_TO_ARTIFACTORY_REPO>/jd-bulk-messenger-1.18.0-RC1-*.war"
You can further tune the command according to your need. Check this link to understand more.
Also yes 180MB is big to cache in CI build.
Does anyone know how to create a remote repo that pulls packages from https://services.gradle.org/distributions/ ?
This post seems to indicate it's possible, but I haven't had any luck.
This post refers to a video with some instructions, but those don't appear to apply to the version we're on (v7.15).
I suspect I probably need a custom layout, but the file names don't seem to play nicely with the parts Artifactory is expecting.
Here is one of my attempts:
and set this in the gradle-wrapper.properties:
distributionUrl=https://<server_name>:443/artifactory/gradle-dist/distributions/gradle-6.8-bin.zip
But it does not work. I'm not able to browse the repo in the Artifactory website nor can I execute the build.
To use Artifactory as a source for Gradle distributions, do the following:
Create a remote generic repository in Artifactory with the URL pointing to https://services.gradle.org/distributions.
Create the Gradle wrapper. As instructed in the Gradle wrapper documentation, you must provide the full URL to the Gradle distibution zip:
gradle wrapper --gradle-distribution-url=<artifactory-url>/gradle-dist/gradle-5.6.4-bin.zip
If authentication is needed, you can add username and password as system properties when running the Gradle commands:
./gradlew --version -Dgradle.wrapperUser=<artifactory-username> -Dgradle.wrapperPassword=<artifactory-password>
Read more:
Artifactory remote repositories
The Gradle wrapper
I have looked up various Q&A's on how to use the artifactory features offered by GitLab, and they all talk about either JFrog (a.k.a Artifactory) or Nexus or something else. GitLab says that we could use it as Artifact management, and I was able to generate artifacts. But I am stuck now since I am completely lost on how to use this.
Here is the script I use to generate artifact using Gradle:
artifacts:
paths:
- build/libs/*.jar
Can anyone guide me on how I could refer to an artifact in my repo during CI/CD. Thanks in advance.
You can read up on them in the dependencies section of the Gitlab docs. Some quotes to guide you:
Note that artifacts from all previous stages are passed by default.
So every artifact you build in a prior job of the same pipeline is passed by default.
(...) the artifacts from job:x will be downloaded and extracted in
the context of the build.
In the context of the build means relative to the working path of the job.
To test this, add a job after the one you create the artifact in and add a ls -la command in the next job to see what has been extracted and is ready for use.
In our web-application we manage our continuous integration using TeamCity. So far we have manually added required jars and used an ant script to build and deploy our application. Lately we switched to Maven and added Artifactory to the cycle.
I need to know how to deploy our build artifacts from TeamCity to Artifactory.
I added the Artifactory plugin to TeamCity (following this guide) but when trying to add a new build step I can't seem to find any Artifactory related step (which I expect to find).
Am missing something here?
I don't think it is a separate step but actually a set of options at the end of the Maven build step itself (it should be toward the bottom).
See here for more detail:
http://wiki.jfrog.org/confluence/display/RTF/TeamCity+Artifactory+Plug-in.
Specifically, it says "The 'Deploy maven artifacts' option will only be available when using a 'Maven2' build runner."
My current Jenkins deployment job retrieves war file generated from maven build process from Nexus repository. The deployment is done this way since I can not use hot deployment for my environments. Currently I used parameterized build with Jenkins so I can manually enter the version number for my artifact. Is there a way to configure Maven or Nexus so the artifact generate from the latest trunk build can be accessed from an static URL? For example:
http://mynexus:8081/nexus/content/repository/snapshots/com/somepackage/my-app/trunk/my-app-trunk.war
I don't know a way to do this in Nexus. But you can access the latest successful build from Jenkins, with a URL like this: http://localhost:8080/jenkins/job/jobname/lastSuccessfulBuild/my-app-trunk.war
You have to enable artifact archiving for your war file, then you can access it.
Same issue here, we discovered about :
https://wiki.jenkins-ci.org/display/JENKINS/Maven+Deployment+Linker
Which does the job.
Hope that helps.