繁体   English   中英

如何在ruby / chef中打印git Latest_tag命令的值

[英]How to print the value of a git latest_tag command in ruby / chef

我正在尝试从git repo获取最新的git标记,该标记已克隆到我的EC2 Ubuntu实例中。 以下是我正在使用的厨师食谱,即git.rb

execute 'test' do
cwd 'myapp-codecommit/myfiles'
 #command 'git clone https://'+node[:awscli][:GIT_USER]+':'+node[:awscli][:GIT_PASS]+'@git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxx'
  command '$(git describe --abbrev=0 --tags)'
  puts "output is #{command}"

end

输出:EC2日志

Use `bundle show [gemname]` to see where a bundled gem is installed.
output is $(git describe --abbrev=0 --tags)
[2018-07-13T12:04:28+00:00] INFO: Processing execute[test] action run 
Error executing action `run` on resource 'execute[test]'
Mixlib::ShellOut::ShellCommandFailed
Expected process to exit with [0], but received '127'
---- Begin output of $(git describe --abbrev=0 --tags) ----
STDOUT:
STDERR: sh: 1: master-1.0.177: not found
---- End output of $(git describe --abbrev=0 --tags) ----
Ran $(git describe --abbrev=0 --tags) returned 127
Resource Declaration:
# In /var/chef/runs/bb7cdd55-4fa8-4979-8485-dc5706d9db32/local-mode-cache/cache/cookbooks/deployfile/recipes/git.rb
3: execute 'test' do
4:     cwd 'myapp-codecommit/myfiles'
5:   #command 'git clone https://'+node[:awscli][:GIT_USER]+':'+node[:awscli][:GIT_PASS]+'@git-codecommit.us-east- 1.amazonaws.com/v1/repos/xxxxxxxx'
6:   command '$(git describe --abbrev=0 --tags)'
7:
8:   puts "output is #{command}"
9:
10: end

正如我们在输出日志中看到的那样,我能够在(STDERR)下获得最新标签,即master-1.0.177,但是我希望将最新标签即(master-1.0.177)打印为

output is master-1.0.177

我要去哪里

output is $(git describe --abbrev=0 --tags)

Chef资源没有输出值。 您可能想要的是shell_out!一些用法shell_out! 辅助方法,但您必须更明确地说明最终要完成的工作。 这是为了进行一些快速调试吗?

编辑:

您想要这样的东西:

# You can swap in some other resource like s3_file, the principle is the same.
remote_file "download the artifact" do
  source lazy {
    git_describe = shell_out!('git describe --abbrev=0 --tags', cwd: '/path/to/myapp-codecommit/myfiles').stdout.strip
    "https://something/path/to/myapp-#{git_describe}.jar"
  }
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM