问题描述
我正在寻找一种简单干净的方法来将使用GitLab CI构建的人工制品发布到Artifactory.
我能够发现 https://gitlab.com/gitlab-org/omnibus/blob/af8af9552966348a15dc1bf488efb29a8ca27111/lib/omnibus/publishers/artifactory_publisher.rb ,但我找不到任何有关如何配置它以使其正常工作的文档./p>
注意:我正在寻找gitlab_ci.yaml方法,而不是在外部实现它.
在基本级别上,可以使用 JFrog CLI 工具.除非您想将配置嵌入到.gitlab-ci.yml
中(我不希望这样做),否则您首先需要运行(在运行程序上):
jfrog rt c
默认情况下,这将提示您输入Artifactory URL和API密钥.输入这些项目后,您会发现~/.jfrog/jfrog-cli.conf
包含JSON,如下所示:
{
"artifactory": {
"url": "http://artifactory.localdomain:8081/artifactory/",
"apiKey": "AKCp2V77EgrbwK8NB8z3LdvCkeBPq2axeF3MeVK1GFYhbeN5cfaWf8xJXLKkuqTCs5obpzxzu"
}
}
您可以将此文件复制到GitLab运行程序的主目录-在我的情况下为/home/gitlab-runner/.jfrog/jfrog-cli.conf
完成后,跑步者将使用该配置向Artifactory进行身份验证.如果您不想使用API密钥,则还有很多其他的身份验证方法-请查看JFrog CLI文档.
在继续之前,请确保"jfrog"可执行文件位于已知位置,并且具有gitlab-runner用户的执行权限.在这里,您可以在.gitlab-ci.yml
中调用该实用程序-这是node.js
应用程序的一个简单示例,该应用程序会将Git标记作为工件版本传递:
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
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.
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
这篇关于如何从GitLab CI将构建发布到Artifactory?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!