GitLab Templates for JFrog
Connect GitLab CI to Artifactory and publish build-info with JFrog CLI templates.
GitLab Templates for JFrog provide ready-to-copy jobs for connecting GitLab CI to the JFrog Platform. Use them when you want a package-specific starting point for builds or audits. The templates install and configure JFrog CLI, then run standard jf commands in your job.
Note
Start with the package template closest to your build. Use the shared setup include directly when you need a custom job that isn't covered by a template.
Prerequisites
- A GitLab project with CI/CD enabled.
- A JFrog Platform URL and credentials.
- Artifactory repository keys for the package manager used by your job.
curlon Linux and macOS runners.- Network access to
releases.jfrog.io, or a generic remote repository that proxieshttps://releases.jfrog.io/artifactory/.
Store credentials as masked and protected GitLab CI/CD variables. Use one of these combinations:
JF_URLfor anonymous access.JF_URL,JF_USER, andJF_PASSWORDfor basic authentication.JF_URLandJF_ACCESS_TOKENfor access-token authentication. Docker login also requiresJF_USER.- Deploy and publish-build-info permission, and the same build name and number on package and
jf rt build-publishsteps.
Before You Begin
Match repository keys to the package type in the template. For more information, see How Build Integration Works and Choose Plugin, CLI, or CI Wrapper.
Build and Deploy a Maven Project
This example builds and deploys a Maven project and publishes its build-info.
To build and deploy a Maven project with a GitLab template:
- Configure these GitLab CI/CD variables with your Artifactory repository keys:
ARTIFACTORY_VIRTUAL_RELEASE_REPOARTIFACTORY_VIRTUAL_SNAPSHOT_REPOARTIFACTORY_LOCAL_RELEASE_REPOARTIFACTORY_LOCAL_SNAPSHOT_REPO
- Add this job to
.gitlab-ci.yml:
default:
image: maven:3.8.6-openjdk-11-slim
include:
- remote: "https://releases.jfrog.io/artifactory/jfrog-cli/gitlab/v2/.setup-jfrog-unix.yml"
jfrog-maven-build:
script:
- !reference [.setup_jfrog, script]
- jf mvn-config --repo-resolve-releases "$ARTIFACTORY_VIRTUAL_RELEASE_REPO" --repo-resolve-snapshots "$ARTIFACTORY_VIRTUAL_SNAPSHOT_REPO" --repo-deploy-releases "$ARTIFACTORY_LOCAL_RELEASE_REPO" --repo-deploy-snapshots "$ARTIFACTORY_LOCAL_SNAPSHOT_REPO"
- jf mvn package deploy
- jf rt build-publish
after_script:
- !reference [.cleanup_jfrog, script]The setup script exports the build name as $CI_PROJECT_PATH_SLUG-$CI_COMMIT_REF_NAME and the build number as $CI_PIPELINE_ID. A successful job uploads the Maven artifacts and publishes that build run to Artifactory.
Verify the Published Build
Open Builds in Artifactory and find the build name derived from the GitLab project and branch. The build run should use the GitLab pipeline ID as its number.
You can also verify the connection in a job with:
jf rt pingUse the Shared Setup Script
Every package template includes a hidden .setup_jfrog job and a .cleanup_jfrog job. Reference setup before your jf commands and cleanup in after_script.
For Windows runners, include:
include:
- remote: "https://releases.jfrog.io/artifactory/jfrog-cli/gitlab/v2/.setup-jfrog-windows.yml"You can also vendor the script and include it with local, or keep it in another GitLab project and include it with project and file.
Set Up an Air-Gapped Download Path
Set up this path to avoid direct runner access to releases.jfrog.io.
To set up an air-gapped download path:
- Copy the setup script into a repository available to GitLab.
- Create a generic remote repository in Artifactory that points to
https://releases.jfrog.io/artifactory/. - Set
JF_RELEASES_REPOto that repository key.
The setup script then downloads JFrog CLI through your JFrog Platform.
Available Templates
JFrog provides build and audit templates for:
- .NET
- Go
- Gradle
- Maven
- npm
- NuGet
- pip
- Pipenv
- Yarn Berry
Build templates configure repositories and run the package command. Audit templates prepare the dependency graph needed by that package manager and run jf audit.
Configuration Reference
The templates and the setup script use the following variables.
| Variable | Purpose |
|---|---|
JF_URL | JFrog Platform URL. |
JF_USER | JFrog user for basic authentication and authenticated Docker operations. |
JF_PASSWORD | Password for basic authentication. |
JF_ACCESS_TOKEN | JFrog access token. |
JF_DOCKER_REGISTRY | Replace GitLab's default Docker registry variables with an Artifactory Docker registry. |
JF_RELEASES_REPO | Generic remote repository used to download JFrog CLI through Artifactory. |
JFROG_CLI_BUILD_PROJECT | JFrog project key for build commands. |
JFROG_CLI_VERSION | JFrog CLI version to install. The setup script requires 2.17.0 or later. |
Pipeline Considerations
- Keep setup and cleanup in the same job.
- Build-info collected in separate jobs on ephemeral runners isn't automatically combined.
- Pin the container images used by your jobs according to your organization's supply-chain policy.
- The templates run ordinary JFrog CLI commands. You can add supported CLI flags after validating them with the installed CLI version.
Troubleshooting
The following table lists common symptoms and how to resolve them.
| Symptom | Cause | Resolution |
|---|---|---|
jf: command not found | The setup reference didn't run in this job. | Add !reference [.setup_jfrog, script] before the first jf command. |
| Authentication fails | Variables are missing, unprotected, or unavailable on the branch. | Check GitLab variable scope and use one supported credential combination. |
| CLI download fails | The runner can't reach releases.jfrog.io. | Configure JF_RELEASES_REPO and include a locally available setup script. |
| Docker login fails with an access token | JF_USER is missing. | Set JF_USER in addition to JF_ACCESS_TOKEN. |
| Build is missing from Artifactory | Build publish didn't run or failed. | Run jf rt build-publish after the package command and inspect that line's output. |
Related Topics
Updated about 1 month ago
