bash - 如何在 bash 中捕获 gitlab-runner 的输出

标签 bash gitlab-ci-runner

为什么当我写入终端时

#!/bin/bash
out=`gitlab-runner list`
echo "list: ${out}"

out 变量仍然为空并且命令的输出始终显示在终端中? Install Gitlab Runner

我如何捕获这个输出?

最佳答案

gitlab-runner list 在 stderr 上输出列表,因此您不会将其捕获为 stdout 的输出。

参见Bash how do you capture stderr to a variable?

并将脚本更改为:

#!/bin/bash
out="$(gitlab-runner list 2>&1)"
echo "list: ${out}"

关于bash - 如何在 bash 中捕获 gitlab-runner 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52324897/

相关文章:

linux - 定期列出文件的 Bash 脚本

bash - bash 脚本如何对后台任务执行相当于 Ctrl-C 的操作?

来自共享 Gitlab 运行器的 SSH 停止工作

continuous-integration - 基于正则表达式的规则子句在 GitLab CI 中不起作用

go - 在 Script 部分的 .gitlab-ci.yml 中调用 GO 二进制文件并捕获响应

bash - 查找文件名中的空格

linux - 在内部使用 sudo 命令运行脚本时出现问题

python - 如何确保 slurm 中的 python 提交脚本位于发出 sbatch 命令的位置?

gitlab - 本地运行者文件存储在哪里?

docker - 无法为 gitlab-ci 运行构建