Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish builds to Artifactory from GitLab CI?

I am looking for an easy and clean way to publish artefacts build with GitLab CI onto Artifactory.

I was able to spot https://gitlab.com/gitlab-org/omnibus/blob/af8af9552966348a15dc1bf488efb29a8ca27111/lib/omnibus/publishers/artifactory_publisher.rb but I wasnt able to find any documentation regarding how I am supposed to configure it to make it work.

Note: I am looking for a gitlab_ci.yaml approach, not as in implementing it externally.

like image 398
sorin Avatar asked Sep 07 '15 16:09

sorin


People also ask

How do I upload builds to Artifactory?

You log in to Artifactory as an administrator/user which has access to deploy artifacts, click on "Deploy" tab, browse for the Artifactory file and once you select the file, click on "Upload" button.

How do I use GitLab Artifactory?

.gitlab-ci.yml sample Navigate to the job in the GitLab CI UI to view the build process and logs. Log into Artifactory and navigate to the Artifact Repository Browser to view your published artifacts in Artifactory. Navigate to the Build Browser to view the build information. That's it!

Does GitLab have Artifactory?

Artifactory is integrated with GitLab letting your GitLab builds resolve dependencies from Artifactory. Using JFrog CLI, you can also deploy your GitLab builds, along with exhaustive build information, to Artifactory.


1 Answers

At a basic level, this can be done with the JFrog CLI tools. Unless you want to embed configuration in your .gitlab-ci.yml (I don't) you will first need to run (on your runner):

jfrog rt c

This will prompt for your Artifactory URL and an API key by default. After entering these items, you'll find ~/.jfrog/jfrog-cli.conf containing JSON like so:

    {
      "artifactory": {
        "url": "http://artifactory.localdomain:8081/artifactory/",
        "apiKey": "AKCp2V77EgrbwK8NB8z3LdvCkeBPq2axeF3MeVK1GFYhbeN5cfaWf8xJXLKkuqTCs5obpzxzu"
      }
    }

You can copy this file to the GitLab runner's home directory - in my case, /home/gitlab-runner/.jfrog/jfrog-cli.conf

Once that is done, the runner will authenticate with Artifactory using that configuration. There are a bunch of other possibilities for authentication if you don't want to use API keys - check the JFrog CLI docs.

Before moving on, make sure the 'jfrog' executable is in a known location, with execute permissions for the gitlab-runner user. From here you can call the utility within your .gitlab-ci.yml - here is a minimal example for a node.js app that will pass the Git tag as the artifact version:

stages:
  - build-package
build-package:
  stage: build-package
  script:
    - npm install
    - tar -czf test-project.tar.gz *
    - /usr/local/bin/jfrog rt u --build-name="Test Project" --build-number="${CI_BUILD_TAG}" test-project.tar.gz test-repo
like image 190
Andrew Snell Avatar answered Sep 27 '22 17:09

Andrew Snell