如何绕过 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 的默认密码是什么 的相关文章

  • 我的 sudo 命令不起作用[关闭]

    Closed 这个问题是无关 help closed questions 目前不接受答案 我有一个 mac 10 8 2 mountain lion 当我尝试使用 sudo 命令时 我得到这个 sudo private etc sudoer
  • 如何使用 GitLab CI only:changes with only:refs?

    My gitlab ci yml配置有这样的工作 Lint dummy stage prepare tags my tag only refs merge requests changes Thorfile script bin true
  • 使用终端(或 Shell)将文件的一部分复制/粘贴到另一个文件中

    我正在尝试将 txt 文件的一部分从行号 n 复制到行号 n y 假设 1000 到 1000000 我尝试过与运营商合作sed 并且失败了 这是我尝试过的命令 sed n 1000 1000000p path first file gt
  • 如何在 Linux/Unix 上根据文件类型添加文件扩展名?

    这是一个关于 Unix shell 脚本 任何 shell 的问题 但任何其他 标准 脚本语言解决方案也将受到赞赏 我有一个充满文件的目录 其中文件名是这样的哈希值 fd73d0cf8ee68073dce270cf7e770b97 fec8
  • 编写健壮的 shell 脚本有哪些规则?

    I recently erased part of my home directory with a shell script I wrote Fortunately I did hit Ctrl C fast enough to avoi
  • 无论 Rosetta 如何,获取 M1 Mac 的真实架构

    我需要检索 Mac 的真实架构 无论该进程是否通过 Rosetta 运行 现在在 Node js 中 process arch回报x64并在外壳中 uname m回报x86 64 感谢 Ouroborus 这张纸条 https develo
  • PHP 中是否有相当于 subprocess 的东西?

    在 Java 和 Python 中 你有ProcessBuilder or 子流程 https docs python org 2 library subprocess html可让您使用未转义字符串轻松启动进程的模块 例如 ls some
  • MongoDB - 编辑器变量 - MongoDB shell - Windows 7

    EDITOR 变量功能真的可以在 Windows 7 上使用吗 我正在读一篇文章 说一旦我们设置了 EDITOR 变量在 mongorc js 中 我们只需在 shell 中输入 编辑变量名 and var name将被加载到编辑器中 在我
  • 如何 grep 文件中不区分大小写的字符串?

    我有一个文件file1其结尾为Success OR success 我想要grep为了这个词success以一种不区分大小写的方式 我写了以下命令 但它区分大小写 cat file1 grep success 我怎样才能改变它 以便它ret
  • Linux shell 根据第二列对文件进行排序?

    我有一个这样的文件 FirstName FamilyName Address PhoneNumber 如何按 FamilyName 排序 如果这是 UNIX sort k 2 file txt 您可以使用多个 k用于对多列进行排序的标志 例
  • GitLab CI - 添加标签时避免构建

    添加 git 标签时如何防止触发 gitlab ci 管道 我在本地运行此命令 而不是在 gitlab ci 作业中运行 git tag a xyz 然后推送标签 这会触发各种管道 我想排除其中一些管道的运行 我正在尝试对诸如以下问题的想法
  • kubernetes 上的 gitlab-ci 缓存与 minio-service 不再工作

    我正在运行 gitlab 10 4 3 和 gitlab runner 10 4 0 作为 kubernetes 部署 带有 kubernetes runner 和一个用于缓存的 minio server 我是按照安装的gitlab 文档
  • 如何在同一实例中运行 Gitlab CI 作业

    我已经自动缩放了 gitlab runnerAWS现货实例 而且效果很好 我在运行作业时遇到问题 下面是我的 gitlab ci yml它有两个阶段 stages build dev1 build build stage build scr
  • 如何获取与 shell 中的文件名模式匹配的所有文件的总文件大小?

    我正在尝试仅使用 shell 来计算与文件名模式匹配的所有文件 在目录树中 的总大小 以字节为单位 这是我到目前为止所拥有的 find name undo exec stat c s awk 总计 1 END 打印总计 有没有更简单的方法来
  • 有哪些基于对象的 shell?

    我打算写一个面向对象的shell 基于Python 我已经有很多想法了 但在实现它之前 我想通过一些现有的 shell 来激发我的灵感 我所说的面向对象的基本意思是 参数不仅仅是字符串数组 而且是对象数组 返回值也是一个对象 不仅有 std
  • system 和 shell_exec 之间的区别

    有什么区别shell exec and systemPHP 中的方法 两者都采用单个命令行参数并在 PHP 中运行 使用其中一种比另一种更好吗 请参阅此处的解释 http chipmunkninja com Program Executio
  • 如何并行执行4个shell脚本,我不能使用GNU并行?

    我有4个shell脚本dog sh bird sh cow sh和fox sh 每个文件使用 xargs 并行执行 4 个 wget 来派生一个单独的进程 现在我希望这些脚本本身能够并行执行 由于某些我不知道的可移植性原因 我无法使用 GN
  • 将 JSON 导出到环境变量

    如果我有这样的 JSON hello1 world1 testk testv 我想将每个键值对导出为环境变量 如何通过 shell 脚本来做到这一点 例如 当我在终端上写时 echo hello1 world1应该打印其他键值对吗 注意 上
  • Gitlab CI - $CI_COMMIT_TAG 为空

    构建时 我需要在 gitlab ci yml 中上次推送的 git 提交的标记值 在构建过程中 我构建了一个 docker 镜像 构建完成后 我想推送这个带有与我的 git 提交相同标签的镜像 到目前为止我的理解是环境变量 CI COMMI
  • 如何制作 Bash 脚本来查找项目中未使用的图像?

    如何制作一个 Bash shell 脚本 它可以识别所有 jpg gif 和 png 文件 然后识别文件夹中任何文本文件中哪些文件未通过 url href 或 src 链接 这就是我开始的 但我最终得到了与我想要的相反的结果 我不想知道引用

随机推荐