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 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地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-