自定义脚本中的git push命令 - 如何安静地执行此操作?

时间:2021-11-30 08:03:28

In a Ruby script, I have a set of git commands. I would like to prevent the output of the git push from being displayed in the console (no output or written in amp file)

在Ruby脚本中,我有一组git命令。我想阻止git push的输出显示在控制台中(无输出或写入放大器文件)

git push origin master
   Counting objects: 440, done.
   Delta compression using up to 4 threads.
   Comprssing objects: 100% (405/405), done.
   Writing objects: 100% (440/440), 353.50 KiB | 0 bytes/s, done.
   Total 440 (delta 115), reused 0 (delta 0)
   To git@bitbucket.org:myname/mygitrepo.git
   + 184a611...a52775d master -> master

As I am using steps in my script, this output is inserted in the current step report flow ... messing it. What should I do to suppress that output?

当我在脚本中使用步骤时,此输出将插入当前步骤报告流程中......弄乱它。我该怎么做才能抑制输出?

UPDATE

I am running a commands set, I am interested to detect ONLY success or failure of the whole set ...

我正在运行一个命令集,我有兴趣只检测整个集合的成功或失败...

%x[ 
cd "#{@project_path}"
git init 2> /dev/null
cp "#{@dockerfile_template}" "#{@project_path}"
git add --all 2> /dev/null
git commit -m "first commit" 2> /dev/null
git remote add origin "#{@project_repository}" 2> /dev/null
git push -u origin master 2> /dev/null
]

if $?.success?

3 个解决方案

#1


You could also combine stdout and stderr to /dev/null

您还可以将stdout和stderr组合到/ dev / null

git push origin master > /dev/null 2>&1

But be aware that if error comes out, you won't be able to see it.

但请注意,如果出现错误,您将无法看到它。

#2


Maybe you want the script to run git push quietly only in case of success? Then you can try this

也许你希望脚本只有在成功的情况下才能安静地运行git push?然后你可以试试这个

Dir.chdir "/path/to/repo" do
  output=`git push origin master 2>&1`
  ret=$?.exitstatus
  if (ret != 0) then
    puts output
  end
end

#3


Try redirecting to /dev/null. ie, use the command:

尝试重定向到/ dev / null。即,使用命令:

    git push origin master > /dev/null

Or possibly (if get outputs to stderr):

或者可能(如果获得输出到stderr):

    git push origin master 2> /dev/null

#1


You could also combine stdout and stderr to /dev/null

您还可以将stdout和stderr组合到/ dev / null

git push origin master > /dev/null 2>&1

But be aware that if error comes out, you won't be able to see it.

但请注意,如果出现错误,您将无法看到它。

#2


Maybe you want the script to run git push quietly only in case of success? Then you can try this

也许你希望脚本只有在成功的情况下才能安静地运行git push?然后你可以试试这个

Dir.chdir "/path/to/repo" do
  output=`git push origin master 2>&1`
  ret=$?.exitstatus
  if (ret != 0) then
    puts output
  end
end

#3


Try redirecting to /dev/null. ie, use the command:

尝试重定向到/ dev / null。即,使用命令:

    git push origin master > /dev/null

Or possibly (if get outputs to stderr):

或者可能(如果获得输出到stderr):

    git push origin master 2> /dev/null