如何绕过 gitlab-runner 要求输入 sudo 命令的密码或 gitlab-runners 的默认密码是什么

2023-11-30

我是 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

但是,我发现usermodmacOS 上不存在。所以我尝试使用提到的另一种方式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?。剩下我所做的一切只是为了解决它。


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何绕过 gitlab-runner 要求输入 sudo 命令的密码或 gitlab-runners 的默认密码是什么 的相关文章

  • 使用 Jenkins 运行 ios-sim

    我正在尝试使用以下命令从命令行启动我的应用程序ios sim https github com downloads pegli ios sim ios sim xcode4 3 tar gz但这就是我得到的 Started by user
  • 使用脚本自动输入 SSH 密码

    我需要创建一个自动向 OpenSSH 输入密码的脚本ssh client 假设我需要通过 SSH 进入myname somehost用密码a1234b 我已经尝试过 bin myssh sh ssh myname somehost a123
  • shell脚本“x$VARIABLE”中x的用途[重复]

    这个问题在这里已经有答案了 我正在查看一些 shell 脚本 comarison shcu 中 x 的用途是什么 if x USER x RUN AS USER then su RUN AS USER c CATALINA HOME bin
  • linux下如何获取昨天和前天?

    我想在变量中获取 sysdate 1 和 sysdate 2 并回显它 我正在使用下面的查询 它将今天的日期作为输出 bin bash tm date Y d m echo tm 如何获取昨天和前天的日期 这是另一种方法 对于昨天来说 da
  • vscode通过SSH连接gitlab的问题

    我在尝试通过 SSH 连接到 GitLab 远程存储库时遇到问题 这里是迄今为止完成的步骤 成功生成 SSH 密钥 管理人员将密钥添加到存储库中 因此当我访问 GitLab 网站时 我可以提交和发布分支 我无法从 VSCODE 发布分支并收
  • Linux shell 脚本:十六进制数字到二进制字符串

    我正在 shell 脚本中寻找一些简单的方法来将十六进制数字转换为 0 和 1 字符的序列 Example 5F gt 01011111 是否有任何命令或简单的方法来完成它 或者我应该为其编写一些开关 echo ibase 16 obase
  • 如何让“grep”从文件中读取模式?

    假设有一个很大的文本文件 我只想打印与某些模式不匹配的行 显然 我可以使用egrep v patter1 pattern2 pattern3 现在 如果所有这些模式都在一个文本文件中怎么办 最好的制作方法是什么egrep从文件中读取模式 g
  • 如何在lua中获取shell脚本的返回码?

    我正在lua中执行一个脚本 os execute sh manager scripts update system sh f 我想获得脚本的输出 如果退出状态为 7 则返回 7 I tried local output os execute
  • bash 变量中的 Linux 鞭尾/对话框参数错误

    有人可以解释为什么下面的代码不起作用吗 我要疯狂地想找出答案 bin bash TEST M1 1 wire Interface ON echo TEST RESULT dialog title Config Modules State c
  • xsel -o 对于 OS X 等效项

    是否有一个等效的解决方案可以在 OS X 中抓取选定的文本 就像适用于 Linux 的 xsel o 一样 只需要当前的选择 这样我就可以在 shell 脚本中使用文本 干杯 埃里克 你也许可以安装xsel在 MacOS 上 更新 根据 A
  • 仅当重复行与模式匹配时才删除它们

    这个问题 https stackoverflow com questions 1444406 how can i delete duplicate lines in a file in unix有一个很好的答案说你可以使用awk seen
  • 拆分字符串以仅获取前 5 个字符

    我想去那个地点 var log src ap kernelmodule 10 001 100 但看起来我的代码必须处理 ap kernelmodule 10 002 100 ap kernelmodule 10 003 101 等 我想使用
  • ReferenceError:MongoDB shell 中未定义 require

    我尝试通过 Windows 命令 Windows 8 1 从 Mongo 客户端连接 MongoDB 当我使用require 在 javascript 中 我遇到如下错误 有人有同样的问题吗 我有错过任何一个吗require有关的npm安装
  • 有一种简单的方法可以忽略时间戳来区分日志文件吗?

    我需要比较两个日志文件 但忽略每行的时间戳部分 确切地说是前 12 个字符 有没有一个好的工具 或者一个聪明的 awk 命令 可以帮助我 根据您使用的 shell 您可以改变方法 Blair https stackoverflow com
  • 从 PL/SQL 调用 shell 脚本,但 shell 以 grid 用户而非 oracle 身份执行

    我正在尝试使用 Runtime getRuntime exec 从 Oracle 数据库内部执行 shell 脚本 在 Red Hat 5 5 上运行的 Oracle 11 2 0 4 EE CREATE OR REPLACE proced
  • shell脚本中关联数组的时间复杂度

    我想知道在 shell 脚本中使用关联数组时如何构造 实现 另外 我想知道基于 shell 脚本的关联数组的时间复杂度是否是最佳的 因为我们可以使用字母和数字作为它们各自的键 编辑 他们使用什么哈希函数 如果您使用关联数组 则不能通过 使用
  • shell脚本中的\r字符

    我在尝试执行 shell 脚本时收到以下错误 r command not found line 2 请提出同样的解决方案 以下是脚本中使用的初始行 bin sh if lt 1 then echo ERROR Environment arg
  • 如何执行“sudo nvm”?

    在我的 Mac 上 我想将一些需要 su 权限的包迁移到另一个节点版本 我使用 homebrew 安装 nvm 现在我需要执行 sudo nvm 或 reinstall packages将失败 me MacBook sudo nvm sud
  • chown:不允许操作

    我有问题 我需要通过 php 脚本为系统中的不同用户设置文件所有者权限 所以我通过以下命令执行此操作 其中 1002 是系统的用户 ID file put contents filename content system chown 100
  • 有没有办法让我简化这些回声? [复制]

    这个问题在这里已经有答案了 我仍在学习如何编写 shell 脚本 并且我面临着一个挑战 让我更容易回显 Name1 Name2 Name15 我不太确定从哪里开始 我已经想法 但如果我搞砸了 我不想看起来很傻 有什么帮助吗 我实际上还没有尝

随机推荐