Gitlab CI/CD:生成带有可执行文件的版本

如何解决Gitlab CI/CD:生成带有可执行文件的版本

我正在尝试通过 Gitlab 使用的 ci/cd 管道系统生成具有可执行文件的版本。目的是将可执行文件用作另一个项目中发布的一部分,以生成 Visual Studio Code Snippets 作为该项目 ci/cd 管道系统的一部分。这是我的一个爱好项目,旨在了解 ci/cd。

用于生成可执行文件的存储库:

以及为以下项目生成片段的示例项目:

这个问题主要是关于以前的存储库,但为了防止 xy problem,我决定添加我正在尝试做的整体范围。

这是写这篇文章时的 .yml 文件:

# This file is a template,and might need editing before it works on your project.
# To contribute improvements to CI/CD templates,please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Bash.gitlab-ci.yml

# See https://docs.gitlab.com/ee/ci/yaml/README.html for all available options

# you can delete this line if you're not using Docker

stages:
  - build
  - upload
  - release

# determines where packages are installed,required for caching as that 
# can only happen for a folder inside the repository
variables:
  STACK_ROOT: "${CI_PROJECT_DIR}/.stack-root"
  PACKAGE_REGISTRY_URL: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}
# cache everything stack related so that libraries do not need to be rebuild
cache:
  paths:
    - .stack-work/
    - .stack-root/

build:

  only:
    - master

  # refers back to the stages defined at the top of this file
  stage: build

  # allows us to have haskell build tools
  image: haskell:9

  # allows us to keep track of the executable
  artifacts:  
    expire_in: 30 days
    paths:
      - source/bin/

  # things that need to be done during this job
  script:
      # build the project
    - echo ${PACKAGE_REGISTRY_URL}
    - cd source
    - stack update
    - stack build --copy-bins
    - stack clean

upload:
  stage: upload
  image: curlimages/curl:latest

  # we don't need the cache with dependencies here
  cache: {}

  # upload the file to make it available as an asset later
  script:
    - echo "${PACKAGE_REGISTRY_URL}/snippet-generator"
    - |
      curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file "source/bin/snippet-generator" "${PACKAGE_REGISTRY_URL}/source/bin/snippet-generator"


release:
  stage: release
  image: registry.gitlab.com/gitlab-org/release-cli

  # we don't need the cache with dependencies here
  cache: {}

  only:
    - master

  # release should be done manually
  when: manual

  # We recommend the use of `rules` to prevent these pipelines
  # from running. See the notes section below for details.
  except:
    - tags
    
  script:
    - echo "${PACKAGE_REGISTRY_URL}/snippet-generator"
    - >
      release-cli create --name release-branch-$CI_JOB_ID --description release-branch-$CI_COMMIT_REF_NAME-$CI_JOB_ID
      --tag-name job-$CI_JOB_ID --ref $CI_COMMIT_SHA
      --assets-link '{"name":"Snippet Generator","url":"${PACKAGE_REGISTRY_URL}/source/bin/snippet-generator" }'

什么已经在起作用了:

  • 构建阶段:编译源代码并将可执行文件存储为工件。缓存依赖项以加快未来的运行速度。
  • 上传阶段:工件可用,我相信它会被上传。无论是否返回错误 (1),作业都会成功。
  • 发布阶段:这是行不通的。我不断收到错误 (2)。

关于(1),这是日志的一部分:

$ echo "${PACKAGE_REGISTRY_URL}/snippet-generator"
https://gitlab.com/api/v4/projects/24129638/snippet-generator
$ curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file "source/bin/snippet-generator" "${PACKAGE_REGISTRY_URL}/source/bin/snippet-generator"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 11.7M  100    58  100 11.7M     36  7593k  0:00:01  0:00:01 --:--:-- 7590k
{"error":"The provided content-type '' is not supported."}

起初我以为这是 curl 的错误,但回想起来,json 是来自 (gitlab) 服务器的响应。由于它发送的文件的大小,我可以确认它找到了正确的文件:当我手动下载工件时它匹配。但是,我没有设法找到有关它描述的错误的文档,并且不知道这是否是导致上传文件被拒绝的严重错误。

关于(2),这是日志的一部分:

$ echo "${PACKAGE_REGISTRY_URL}/snippet-generator"
https://gitlab.com/api/v4/projects/24129638/snippet-generator
$ release-cli create --name release-branch-$CI_JOB_ID --description release-branch-$CI_COMMIT_REF_NAME-$CI_JOB_ID --tag-name job-$CI_JOB_ID --ref $CI_COMMIT_SHA --assets-link '{"name":"Snippet Generator","url":"${PACKAGE_REGISTRY_URL}/source/bin/snippet-generator" }'
time="2021-07-19T15:27:18Z" level=info msg="Creating Release..." cli=release-cli command=create name=release-branch-1435508632 project-id=24129638 ref=e30341cbdecda9b171589aa1ba767ae5bd7583b3 server-url="https://gitlab.com" tag-name=job-1435508632 version=0.8.0
time="2021-07-19T15:27:18Z" level=warning msg="file does not exist,using string value for --description" cli=release-cli description=release-branch-master-1435508632 error="open /builds/supreme-commander-forged-alliance/other/snippet-generator/release-branch-master-1435508632: no such file or directory" version=0.8.0
time="2021-07-19T15:27:19Z" level=fatal msg="failed to create release: API Error Response status_code: 400 message: Validation failed: Links url is blocked: Only allowed schemes are http,https,ftp" cli=release-cli version=0.8.0

我不明白它是如何构建 URL 'open/builds/supreme-commander-forged-alliance/other/snippet-generator/release-branch-master-1435508632'的。该网址不是我提供的。但是这个网址是从哪里来的呢?它需要什么网址?

总的来说,我有点不知所措,我试过了:

但我只是不知道如何进一步处理它。

解决方法

关于 (1),我认为您在这里使用了错误的 URL。它应该看起来像 $CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/generic/$YOUR_PACKAGE_NAME/$YOUR_PACKAGE_VERSION。您还可以将 --fail 添加到 curl 命令,以便在服务器响应 HTTP 状态代码 >= 400 时让 curl 退出并显示错误。关于 {{1} 的错误消息}},我猜 Content-Type 并不意味着一个,因为您的文件没有扩展名。但是,您可以使用(例如)curl 手动指定它。如果此步骤成功,您应该能够在 GitLab 的包注册表 UI 中看到该文件。

关于 (2),从 GitLab 13.2 开始,您可以使用专用的 release 关键字。从 GitLab 13.12 开始,还支持 asset links

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)> insert overwrite table dwd_trade_cart_add_inc > select data.id, > data.user_id, > data.course_id, > date_format(
错误1 hive (edu)> insert into huanhuan values(1,'haoge'); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive> show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 <configuration> <property> <name>yarn.nodemanager.res