gpt4 book ai didi

Gitlab-如何根据工作管道添加徽章

转载 作者:行者123 更新时间:2023-12-02 05:47:18 25 4
gpt4 key购买 nike

我的目标是根据管道结果显示徽章(例如:enter image description here)。

我有一个私有(private) gitlab ce 综合实例,其中包含以下 .gitlab-ci.yml :

image: python:3.6

stages:
- lint
- test

before_script:
- python -V
- pip install pipenv
- pipenv install --dev

lint:
stage: lint
script:
- pipenv run pylint --output-format=text --load-plugins pylint_django project/ | tee pylint.txt
- score=$(sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' pylint.txt)
- echo "Pylint score was $score"
- ls
- pwd
- pipenv run anybadge --value=$score --file=pylint.svg pylint
artifacts:
paths:
- pylint.svg

test:
stage: test
script:
- pipenv run python manage.py test

所以我想将图像存储在 lint 作业的工件中,并通过徽章功能显示它。

但是我遇到以下问题:当我浏览https://example.com/[group]/[project]/-/jobs/[ID]/artifacts/file/pylint.svg时,我没有看到徽章,而是看到以下消息:

The image could not be displayed because it is stored as a job artifact. You can download it instead.

无论如何,我觉得这是错误的方式,因为即使我可以获得图像,似乎也没有办法从上一个作业中获取图像,因为徽章图像的 gitlab URL 仅支持 %{project_path}、%{project_id}、%{default_branch}、%{commit_sha}

那么如何根据 gitlab 管道中的结果生成的 svg 将徽章添加到 gitlab 项目中?

我的猜测是我可以推送到 .badge 文件夹,但这听起来不像是一个干净的解决方案。

最佳答案

您确实可以获得最新作业的工件(请参阅文档 here ),但技巧是您需要使用稍微不同的 URL:

https://example.com/[group]/[project]/-/jobs/artifacts/[ref]/raw/pylint.svg?job=lint

其中 [ref] 是对您的分支/提交/标签的引用。

说到 Gitlab 中可用的徽章占位符,您可以将 %{default_branch}%{commit_sha} 放入 [ref] 中。这不会让您为每个分支获得正确的徽章,但至少您的默认分支会获得一个。

另请注意,?job=lint 查询参数是必需的,没有它,URL 将无法工作。

关于Gitlab-如何根据工作管道添加徽章,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52228070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com