AWS Cli命令在本地系统中运行正常,但在Jenkins中不起作用。

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

AWS Cli command is running perfectly in local system but not working in Jenkins

问题

I am using this command to create AWS Eventbridge Scheduler. It is working fine when I'm running it locally, but in Jenkins it is not working.

在创建AWS Eventbridge Scheduler时,我使用以下命令。在本地运行时正常工作,但在Jenkins中不起作用。

Error: 错误:
Error parsing parameter '--target': Invalid JSON: Expecting ',' delimiter: line 1 column 188 (char 187)
JSON received: { "Arn": "arn:aws:scheduler:::aws-sdk:ec2:stopInstances", "RoleArn": "arn:aws:iam::9668xxxxxxxx:role/service-role/Amazon_EventBridge_Invoke_Action_On_EC2_Instance_2111992150", "Input": "{"InstanceIds": ["i-0ad766a46xxxxxxxx"]}"}

英文:

I am using this command to create AWS Eventbridge Scheduler. It is working fine when I'm running it locally, but in jenkins it is not working.

aws scheduler create-schedule --name SendEmailOnce --schedule-expression "at(2022-11-01T11:00:00)" --flexible-time-window "{"Mode": "OFF"}" --target '{"Arn": "arn:aws:scheduler:::aws-sdk:ec2:stopInstances", "RoleArn": "arn:aws:iam::96685xxxxxxx:role/service-role/Amazon_EventBridge_Invoke_Action_On_EC2_Instance_2111992150", "Input": "{"InstanceIds": ["i-0ad766a46xxxxxx"]}"}'

I'm creating AWS eventbridge scheduler with this command:
aws scheduler create-schedule --name SendEmailOnce --schedule-expression "at(2022-11-01T11:00:00)" --flexible-time-window "{"Mode": "OFF"}" --target '{"Arn": "arn:aws:scheduler:::aws-sdk:ec2:stopInstances", "RoleArn": "arn:aws:iam::96685xxxxxx:role/service-role/Amazon_EventBridge_Invoke_Action_On_EC2_Instance_2111", "Input": "{"InstanceIds": ["i-0ad766a469xxxxxxx"]}"}'

above written command is working perfectly in local machine but not in jenkins.

Jenkinsfile:
pipeline {
agent any

stages {
    stage('Build') {
        steps {
            sh"""
            aws sts get-caller-identity
            aws scheduler create-schedule --name ${name} \
                --schedule-expression "at(2022-11-01T11:00:00)" \
                --flexible-time-window '{ "Mode": "OFF" }' \
                --target "{"Arn": "arn:aws:scheduler:::aws-sdk:ec2:stopInstances", "RoleArn": "arn:aws:iam::966858xxxxx:role/service-role/Amazon_EventBridge_Invoke_Action_On_EC2_Instance_2111992150", "Input": "{\"InstanceIds\": [\"i-0ad766a46xxxxxx\"]}"}"
            """
        }
    }
}

}

Error:
Error parsing parameter '--target': Invalid JSON: Expecting ',' delimiter: line 1 column 188 (char 187)
JSON received: {"Arn": "arn:aws:scheduler:::aws-sdk:ec2:stopInstances", "RoleArn": "arn:aws:iam::9668xxxxxxxx:role/service-role/Amazon_EventBridge_Invoke_Action_On_EC2_Instance_2111992150", "Input": "{"InstanceIds": ["i-0ad766a46xxxxxxxx"]}"}

答案1

得分: 1

--target的值中将双引号更改为单引号,并删除转义的双引号,如下所示:

--target '{ "Arn": "arn:aws:scheduler:::aws-sdk:ec2:stopInstances", "RoleArn": "arn:aws:iam::9668xxxxxxxx:role/service-role/Amazon_EventBridge_Invoke_Action_On_EC2_Instance_2111992150", "Input": {"InstanceIds": ["i-0ad766a46xxxxxxxx"]}}'。

应该可以正常工作。

英文:

Change double to single quotes in --target value and remove the escaped double quotes, like this:

--target '{"Arn": "arn:aws:scheduler:::aws-sdk:ec2:stopInstances", "RoleArn": "arn:aws:iam::9668xxxxxxxx:role/service-role/Amazon_EventBridge_Invoke_Action_On_EC2_Instance_2111992150", "Input": {"InstanceIds": ["i-0ad766a46xxxxxxxx"]}}'

It should work.

huangapple
  • 本文由 发表于 2023年2月23日 22:24:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75546118.html
匿名

发表评论

匿名网友

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

确定