GitLab CI/CD 管道在构建 Debian 包时找不到 GCC
Posted
技术标签:
【中文标题】GitLab CI/CD 管道在构建 Debian 包时找不到 GCC【英文标题】:GitLab CI/CD Pipeline can't find GCC when building Debian package 【发布时间】:2020-07-23 13:36:30 【问题描述】:TL;DR - 为什么这条管道找不到 gcc
?
在以下管道中,作业失败,因为它在 PATH
中找不到 gcc
。
这是使用官方的 GCC docker 镜像。我也将此工作流程用于另一个项目。
image: gcc
variables:
DEBVER: "1"
VERSION: "0.0.1-alpha"
JSON_PARSER_MIRROR: "https://gitlab.com/oxr463/json-parser/-/jobs/484303930/artifacts/raw"
deb:
stage: build
before_script:
- apt update && apt install -y debhelper devscripts libpam0g-dev
- curl -O "$JSON_PARSER_MIRROR/libjsonparser1.1_1.1.0-1_amd64.deb"
- curl -O "$JSON_PARSER_MIRROR/libjsonparser-dev_1.1.0-1_amd64.deb"
- dpkg -i libjsonparser1.1_1.1.0-1_amd64.deb
- dpkg -i libjsonparser-dev_1.1.0-1_amd64.deb
- mkdir -p build
script:
- which gcc
- export PATH="$PATH:/usr/local/bin"
- tar cvzf "../pam-oauth2_$VERSION.orig.tar.gz" --exclude='.git*' --exclude='*.deb' .
- mv ../*.orig.tar.gz .
- tar -xf *.orig.tar.gz -C build/
- cd build
- debuild -us -uc -d -i'(.*)'
after_script:
- rm -rf build
artifacts:
paths:
- "*.deb"
来源:https://gitlab.com/oxr463/pam_oauth2/-/blob/debian-fix/.gitlab-ci.yml
$ debuild -us -uc -d -i'(.*)'
dpkg-architecture: warning: cannot determine CC system type, falling back to default (native compilation)
dpkg-buildpackage -us -uc -ui -d -i(.*)
dpkg-buildpackage: info: source package pam-oauth2
dpkg-buildpackage: info: source version 0.0.1-alpha-1
dpkg-buildpackage: info: source distribution UNRELEASED
dpkg-buildpackage: info: source changed by Lucas Ramage <ramage.lucas@protonmail.com>
dpkg-architecture: warning: cannot determine CC system type, falling back to default (native compilation)
dpkg-source -i(.*) --before-build .
dpkg-buildpackage: info: host architecture amd64
debian/rules clean
dh clean
dh_auto_clean
make -j1 clean
make[1]: Entering directory '/builds/oxr463/pam_oauth2/build'
rm *.o *.so pam_test pam_oauth2
rm: cannot remove '*.o': No such file or directory
rm: cannot remove '*.so': No such file or directory
rm: cannot remove 'pam_test': No such file or directory
rm: cannot remove 'pam_oauth2': No such file or directory
make[1]: [Makefile:43: clean] Error 1 (ignored)
make[1]: Leaving directory '/builds/oxr463/pam_oauth2/build'
dh_clean
dpkg-source -i(.*) -b .
dpkg-source: info: using source format '3.0 (quilt)'
dpkg-source: info: building pam-oauth2 using existing ./pam-oauth2_0.0.1-alpha.orig.tar.gz
dpkg-source: info: building pam-oauth2 in pam-oauth2_0.0.1-alpha-1.debian.tar.xz
dpkg-source: info: building pam-oauth2 in pam-oauth2_0.0.1-alpha-1.dsc
debian/rules build
make: 'build' is up to date.
debian/rules binary
dh binary
dh_update_autotools_config
debian/rules override_dh_auto_configure
make[1]: Entering directory '/builds/oxr463/pam_oauth2/build'
dh_auto_configure -- --with-pam-dir=/lib/x86_64-linux-gnu/security
make[1]: Leaving directory '/builds/oxr463/pam_oauth2/build'
dh_auto_build
make -j1
make[1]: Entering directory '/builds/oxr463/pam_oauth2/build'
gcc -g -O2 -fdebug-prefix-map=/builds/oxr463/pam_oauth2/build=. -fstack-protector-strong -Wformat -Werror=format-security -Werror -fPIC -I/system/apps/pam/latest/include -I/system/apps/curl/latest/include -I/system/apps/json-parser/latest/include -Wdate-time -D_FORTIFY_SOURCE=2 -c -o pam_oauth2_core.o pam_oauth2_core.c
make[1]: gcc: Command not found
make[1]: *** [<builtin>: pam_oauth2_core.o] Error 127
make[1]: Leaving directory '/builds/oxr463/pam_oauth2/build'
dh_auto_build: make -j1 returned exit code 2
make: *** [debian/rules:6: binary] Error 2
dpkg-buildpackage: error: debian/rules binary subprocess returned exit status 2
debuild: fatal error at line 1182:
dpkg-buildpackage -us -uc -ui -d -i(.*) failed
来源:https://gitlab.com/oxr463/pam_oauth2/-/jobs/485171400
参考:
https://hub.docker.com/_/gcc https://gitlab.com/oxr463/json-parser/-/blob/debian/.gitlab-ci.yml【问题讨论】:
【参考方案1】:debuild
手册页说(在环境变量部分):
由于环境变量会影响包的构建,因此通常 无意中,debuild 通过删除所有 除了 TERM、HOME、LOGNAME、GNUPGHOME 之外的环境变量, PGPPATH、GPG_AGENT_INFO、FAKEROOTKEY、DEB_*、(C、CPP、CXX、LD 和 F) FLAGS 变量及其 _APPEND 对应项和语言环境 变量 LANG 和 LC_*。如果未设置 TERM,则将其设置为“哑”,并且 PATH 设置为“/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11”。
参考: https://manpages.debian.org/jessie/devscripts/debuild.1.en.html
使用debuild --prepend-path=/usr/local/bin ...
【讨论】:
以上是关于GitLab CI/CD 管道在构建 Debian 包时找不到 GCC的主要内容,如果未能解决你的问题,请参考以下文章
为合并请求触发的管道运行应用 GitLab CI/CD 管道更改