作为部署到服务器的Capistrano Ruby任务的一部分,我希望它输出Git消息并提交刚刚部署的代码。Capistrano/Ruby执行在变量后添加分号
有了这个:
git_message = `git log -1 HEAD --pretty=format:%s`
git_commit = `git rev-parse HEAD`
git_commit = "https://example.com/myorg/myrepo/commit/" + git_commit
execute "echo \"Deployed \\\"#{git_message}\\\": #{git_commit}\" | a_command_that_posts_to_slack"
它的输出是这样的:
Deployed "Merge branch 'feature/some-feature' into develop": https://example.com/myorg/myrepo/commit/0fdfa09fbfe012649fb0a998aa2e99cb5fd7c8b3;
注意分号提交哈希的尽头。我已经使用puts
确认git_commit
不以分号结尾,而git_message
没有分号,并且在它之后也没有。
什么是添加分号,我该如何删除它?
当你说它的输出,你的意思是松弛?我看到你有'a_command_that_posts_to_slack'或许这个命令添加了分号?尝试重定向到一个文件,而不是滚动到该命令。 – ddubs
我在Slack中看到了分号,但我也在终端中看到它。在没有管道的情况下出现相同的分号:'execute“echo \”Deployed \\“#{git_message} \\\”:#{git_commit} \“”' – Hugo