简体   繁体   English

无法从 Jenkins 作业中运行的 shell 脚本解析 aws cli 命令主要版本,但为什么呢?

[英]Unable to parse aws cli command major version from a shell script running in a Jenkins job, but why?

I'm trying to run the following code:我正在尝试运行以下代码:

aws --version | awk '{print $1}' | awk -F/ '{print $2}' | awk -F. '{print $1}'

which should return either 1 or 2 per the major version of aws-cli in the Jenkins node that runs this job.对于运行此作业的 Jenkins 节点中的 aws-cli 主要版本,它应该返回 1 或 2。

I also tried including the #!/bin/bash shebang in the beginning of the code but to no avail.我还尝试在代码的开头包含#!/bin/bash shebang 但无济于事。

For some reason, no matter what I try, I'm unable to parse the major version digit from the output of aws --version .出于某种原因,无论我尝试什么,我都无法从aws --version的输出中解析主要版本数字。

This is the output of the job:这是作业的输出:

[workspace] $ /bin/bash -xe /tmp/jenkins1279490794754365723.sh
+ /usr/local/bin/aws --version
+ /usr/bin/awk '{print $1}'
+ /usr/bin/awk -F/ '{print $2}'
+ /usr/bin/awk -F. '{print $1}'
aws-cli/1.16.198 Python/2.7.16 Linux/4.4.0-1012-aws botocore/1.12.188
Notifying upstream projects of job completion
Finished: SUCCESS

I've tried both absolute and relative path's of the relevant commands but no matter what I get the full output of aws --version rather than just the parsed output.我已经尝试了相关命令的绝对路径和相对路径,但无论我得到aws --version的完整输出,而不仅仅是解析的输出。

Any idea why?知道为什么吗?

尝试更新 awk/gawk 并重新运行您的脚本。

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

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