我是 gitlab runner 的新手,并尝试自动化我的项目,以便每当发布新标签时,它都应该构建一个新的 deb 包。 PS:我用的是mac
下列的thisgitlab 的官方链接来完成我的任务
我的第一个 gitlab-ci.yml 文件是(刚刚在我上面提供的 gitlab 官方链接上给出的):
# Is performed before the scripts in the stages step
before_script:
- source /etc/profile
# Defines stages which are to be executed
stages:
- build
# Stage "build"
run-build:
stage: build
script:
- apt-get install -y libncurses5-dev libglib2.0-dev libgeoip-dev libtokyocabinet-dev zlib1g-dev libncursesw5-dev libbz2-dev
- autoreconf -fvi
- cp COPYING debian/copyright
- dpkg-buildpackage -us -uc
- mkdir build
- mv ../goaccess*.deb build/
# This stage is only executed for new tags
only:
- tags
# The files which are to be made available in GitLab
artifacts:
paths:
- build/*
我最初遇到的上述 gitlab-ci.yml 文件的问题是:
输出1:
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in /home/gitlab-runner/builds/GJ7z2Aym/0/edge_release_management/.git/
Checking out 3d71402b as tag1-test...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:00
$ source /etc/profile
$ apt-get install -y libncurses5-dev libglib2.0-dev libgeoip-dev libtokyocabinet-dev zlib1g-dev libncursesw5-dev libbz2-dev
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit status 1
其中说E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
因此,为了解决上述问题,我想改变brefore_script
部分与此
# Is performed before the scripts in the stages step
before_script:
- source /etc/profile
- echo "Hello, $GITLAB_USER_LOGIN!"
- echo "Hello, $GITLAB_USER_PASSWORD"
# - sudo rm /var/cache/apt/archives/lock
# - sudo rm /var/lib/dpkg/lock
- sudo su
我想删除的地方/var/cache/apt/archives/lock
and /var/lib/dpkg/lock
,因为这是我在 Google 上找到的。当它不起作用时,我尝试过sudo su
。但通过上述更改,我开始遇到这个问题。
输出2:
Getting source from Git repository
00:00
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in /home/gitlab-runner/builds/GJ7z2Aym/0/edge_release_management/.git/
Checking out 7fbaaf4f as testing4...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:00
$ source /etc/profile
$ sudo rm /var/cache/apt/archives/lock
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit status 1
It says sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required
所以,为了解决这个问题,我使用了sudo -S su < $password_secret
如图所示:
# Is performed before the scripts in the stages step
before_script:
- source /etc/profile
- echo "Hello, $GITLAB_USER_LOGIN!"
- echo "Hello, $GITLAB_USER_PASSWORD"
# - sudo rm /var/cache/apt/archives/lock
# - sudo rm /var/lib/dpkg/lock
# - sudo su
- sudo -S su < $password_secret
请注意:我已保存$password_secret
在 Gitlab 变量中,它的值是$password.secret
正如谷歌上的某人所说,这可能是它的价值。我不确定这有多真实。
现在它给了我这个错误:输出3:
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in /home/gitlab-runner/builds/GJ7z2Aym/0/edge_release_management/.git/
Checking out 0b8ab538 as 26...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:02
$ source /etc/profile
$ echo "Hello, $GITLAB_USER_LOGIN!"
Hello, user!
$ echo "Hello, $GITLAB_USER_PASSWORD"
Hello,
$ sudo -S su < $password_secret
[sudo] password for gitlab-runner: Sorry, try again.
[sudo] password for gitlab-runner:
sudo: no password was provided
sudo: 1 incorrect password attempt
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit status 1
请注意:我也用过上面提到的方法here
但是,我发现usermod
macOS 上不存在。所以我尝试使用提到的另一种方式here using dscl
。但它仍然向我展示Output 3 only
现在我厌倦了,无法想出任何其他可能的方法来解决这个问题。我想我已经尝试了几乎所有针对此问题发布的内容(这可能根本不正确,因为我相信必须有一些解决方案)。谁能帮我解决这个问题吗?
Summary:基本上我的主要问题显示在第一个输出中,其中显示E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
。剩下我所做的一切只是为了解决它。