Jenkins Webhook Header 作为 Shell 脚本的参数
Jenkins Webhook Header as Argument to Shell script
只要出现以下示例事件的 EC2 Spot 实例中断警告,我就会尝试使用 curl 命令通过 webhook 触发 Jenkins 作业。所有这些都将在来自 CloudWatch 事件触发器的 AWS lambda 中完成。
{
"version": "0",
"id": "1e5527d7-bb36-4607-3370-4164db56a40e",
"detail-type": "EC2 Spot Instance Interruption Warning",
"source": "aws.ec2",
"account": "123456789012",
"time": "1970-01-01T00:00:00Z",
"region": "us-east-1",
"resources": [
"arn:aws:ec2:us-east-1b:instance/i-0b662ef9931388ba0"
],
"detail": {
"instance-id": "i-0b662ef9931388ba0",
"instance-action": "terminate"
}
}
我的目标是从事件中获取 instance-id 并将其作为 header 传递给 jenkins webhook,在该处触发 jenkins 作业并且必须发送此 header作为 jenkins 作业中底层 python 脚本的参数。
我尝试了以下方法,但没有成功。而且我不确定这是不是这样做的。 :)
curl -H 'param: instance' https://jenkins.url/generic-webhook-trigger/invoke\?token\=jenkins-job
通用 Jenkins webhook 触发器配置如下。
作业中最终的python脚本配置如下。
python maintenance.py $.param
我正在尝试获取类似于下面的最终脚本。如果您知道任何方法,请告诉我如何完成此操作。 TIA
python maintenance.py i-0b662ef9931388ba
我通过添加以下内容解决了这个问题。
在 This project is parameterized
下添加 string parameter
如下所示。
下Generic Webhook Trigger
下我已经添加了Header parameters
现在,我们可以使用 $param
在构建命令中直接传递此参数。
curl 命令现在修改为以下。
curl --location --request POST 'https://jenkins.url/generic-webhook-trigger/invoke\?token\=jenkins-job' --header 'Content-Type: application/json' --header "param: $EVENT_DATA" --data-raw ''
What did I learn from this?
I was too lazy to read the documentation and finally figured it out only after reading it.
只要出现以下示例事件的 EC2 Spot 实例中断警告,我就会尝试使用 curl 命令通过 webhook 触发 Jenkins 作业。所有这些都将在来自 CloudWatch 事件触发器的 AWS lambda 中完成。
{
"version": "0",
"id": "1e5527d7-bb36-4607-3370-4164db56a40e",
"detail-type": "EC2 Spot Instance Interruption Warning",
"source": "aws.ec2",
"account": "123456789012",
"time": "1970-01-01T00:00:00Z",
"region": "us-east-1",
"resources": [
"arn:aws:ec2:us-east-1b:instance/i-0b662ef9931388ba0"
],
"detail": {
"instance-id": "i-0b662ef9931388ba0",
"instance-action": "terminate"
}
}
我的目标是从事件中获取 instance-id 并将其作为 header 传递给 jenkins webhook,在该处触发 jenkins 作业并且必须发送此 header作为 jenkins 作业中底层 python 脚本的参数。
我尝试了以下方法,但没有成功。而且我不确定这是不是这样做的。 :)
curl -H 'param: instance' https://jenkins.url/generic-webhook-trigger/invoke\?token\=jenkins-job
通用 Jenkins webhook 触发器配置如下。
作业中最终的python脚本配置如下。
python maintenance.py $.param
我正在尝试获取类似于下面的最终脚本。如果您知道任何方法,请告诉我如何完成此操作。 TIA
python maintenance.py i-0b662ef9931388ba
我通过添加以下内容解决了这个问题。
在 This project is parameterized
下添加 string parameter
如下所示。
下Generic Webhook Trigger
下我已经添加了Header parameters
现在,我们可以使用 $param
在构建命令中直接传递此参数。
curl 命令现在修改为以下。
curl --location --request POST 'https://jenkins.url/generic-webhook-trigger/invoke\?token\=jenkins-job' --header 'Content-Type: application/json' --header "param: $EVENT_DATA" --data-raw ''
What did I learn from this? I was too lazy to read the documentation and finally figured it out only after reading it.