英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论