AWS Cli CURL在Jenkins管道中使用带有标头

huangapple go评论61阅读模式
英文:

AWS Cli CURL with Header in a Jenkins Pipeline

问题

抱歉,我理解你只需要翻译代码部分,以下是翻译好的部分:

Apologies about this question but I'm running low on ideas about this. We're creating a jenkins pipeline that uses SSM to download a few files to nodes.

The escaping on this seems almost impossible to work out. Even SSM in the command shell is having issues:

    header='Authorization: Bearer NjA5MDg4Mdsfsdfsdfsdfdsfsddsfsr1223434'
    

Then the command:

    aws ssm send-command --instance-ids i-12344556677 --document-name AWS-RunShellScript --parameters "commands=cd /tmp; wget -d --header=${header} https://git.org/projects/files/raw/requirements.txt" --output text --query Command.CommandId --region eu-west-1

I've tried multiple \, different " ' in all sorts of places but I just cannot get it to work.

Example error:

    aws ssm send-command --instance-ids i-1232131212312 --document-name AWS-RunShellScript --parameters 'commands=cd /tmp; wget -d --header='Authorization: Bearer NjA5M33333444444444444444U' https://git.org/projects/files/raw/requirements.txt' --output text --query Command.CommandId --region eu-west-1
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

  aws help
  aws <command> help
  aws <command> <subcommand> help

Unknown options: NjA5M33333444444444444444U https://git.org/projects/files/raw/requirements.txt, Bearer

Has anyone here done this?

Thanks,
英文:

Apologies about this question but I'm running low on ideas about this. We're creating a jenkins pipeline that uses SSM to download a few files to nodes.

The escaping on this seems almost impossible to work out. Even SSM in the command shell is having issues:

header=&#39;Authorization: Bearer NjA5MDg4Mdsfsdfsdfsdfdsfsddsfsr1223434&#39;

Then the command:

aws ssm send-command --instance-ids i-12344556677 --document-name AWS-RunShellScript --parameters &quot;commands=cd /tmp; wget -d --header=${header} https://git.org/projects/files/raw/requirements.txt&quot; --output text --query Command.CommandId --region eu-west-1

I've tried multiple \, different " ' in all sorts of places but I just cannot get it to work.

Example error:

    aws ssm send-command --instance-ids i-1232131212312 --document-name AWS-RunShellScript --parameters &#39;commands=cd /tmp; wget -d --header=&#39;Authorization: Bearer NjA5M33333444444444444444U&#39; https://git.org/projects/files/raw/requirements.txt&#39; --output text --query Command.CommandId --region eu-west-1
usage: aws [options] &lt;command&gt; &lt;subcommand&gt; [&lt;subcommand&gt; ...] [parameters]
To see help text, you can run:

  aws help
  aws &lt;command&gt; help
  aws &lt;command&gt; &lt;subcommand&gt; help

Unknown options: NjA5M33333444444444444444U https://git.org/projects/files/raw/requirements.txt, Bearer

Has anyone here done this?

Thanks,

答案1

得分: 1

如果您因为需要进行严格的命令转义而感到困扰,可以考虑创建一个文件,然后使用cat命令进行转储:

aws ssm send-command --document-name "AWS-RunShellScript" \
   --instance-ids i-12344556677 \
   --parameters "commands=$(cat command.txt)" \
   --output text --query Command.CommandId --region eu-west-1

如果您想要快速的转义修复,您也可以尝试:

header='Authorization: Bearer NjA5MDg4Mdsfsdfsdfsdfdsfsddsfsr1223434'
aws ssm send-command --instance-ids i-12344556677 \
   --document-name AWS-RunShellScript \
   --parameters "commands=['cd /tmp', 'wget -d --header='${header}' https://git.org/projects/files/raw/requirements.txt']" \
   --output text \
   --query Command.CommandId --region eu-west-1
英文:

If you are struggling with running commands due to hard core escaping requirements, you may want to consider creating a file that you can then dump using cat command:

aws ssm send-command --document-name &quot;AWS-RunShellScript&quot; \
   --instance-ids i-12344556677 \
   --parameters &quot;commands=$(cat command.txt)&quot; \
   --output text --query Command.CommandId --region eu-west-1

If you want a quick escaping fix, you can also try:

header=&#39;Authorization: Bearer NjA5MDg4Mdsfsdfsdfsdfdsfsddsfsr1223434&#39;
aws ssm send-command --instance-ids i-12344556677 \
   --document-name AWS-RunShellScript \
   --parameters &quot;commands=[&#39;cd /tmp&#39;, &#39;wget -d --header=\&#39;${header}\&#39; https://git.org/projects/files/raw/requirements.txt&#39;]&quot; \
   --output text \
   --query Command.CommandId --region eu-west-1

huangapple
  • 本文由 发表于 2023年7月6日 22:04:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76629668.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定