[英]IBM Cloud Code Engine: How to overwrite environment variable in cron-invoked job run?
When working with jobs in IBM Cloud Code Engine, I would submit a jobrun for the actual invocation.在 IBM Cloud Code Engine 中处理作业时,我会为实际调用提交一个作业运行。 For the jobrun I can specify environment variables to be passed into the runtime environment (
--env FOO=BAR
).对于作业运行,我可以指定要传递到运行时环境的环境变量(
--env FOO=BAR
)。
How can I do the same when using a cron subscription to trigger the job, ie, to set FOO=BAR
? 使用 cron 订阅触发作业(即设置
FOO=BAR
)时,我该如何做同样的事情?
I believe the correct flag to pass to the CLI is the --ext or --extension.我相信传递给 CLI 的正确标志是 --ext 或 --extension。
% ibmcloud ce subscription cron create --
NAME:
create - Create a cron event subscription.
USAGE:
create --name CRON_SOURCE_NAME --destination DESTINATION_REF [options...]
OPTIONS:
--destination, -d value Required. The name of the resource that will receive events.
--name, -n value Required. The name of the cron event subscription. Use a name that is unique within the project.
--content-type, --ct value The media type of the 'data' or 'data-base64' option. Examples include 'application/json',
'application/x-www-form-urlencoded', 'text/html', and 'text/plain'.
--data, --da value The data to send to the destination.
--data-base64, --db value The base64-encoded data to send to the destination.
--destination-type, --dt value The type of the 'destination'. Valid values are 'app' and 'job'. (default: "app")
--extension, --ext value Set CloudEvents extensions to send to the destination. Must be in NAME=VALUE format. This option can be
specified multiple times. (accepts multiple inputs)
For example:例如:
% ibmcloud ce subscription cron create -d application-5c -n sample-cron-sub --ext FOO=BAR
Creating cron event subscription 'sample-cron-sub'...
Run 'ibmcloud ce subscription cron get -n sample-cron-sub' to check the cron event subscription status.
% ibmcloud ce subscription cron get -n sample-cron-sub
Getting cron event subscription 'sample-cron-sub'...
OK
Name: sample-cron-sub
ID: xxxx
Project Name: susan-project
Project ID: xxxx
Age: 3m16s
Created: 2022-06-06T11:17:17-07:00
Destination Type: app
Destination: application-5c
Schedule: * * * * *
Time Zone: UTC
Ready: true
CloudEvents Extensions:
Name Value
FOO BAR
Events:
Type Reason Age Source Messages
Normal PingSourceSkipped 3m17s pingsource-controller PingSource is not ready
Normal PingSourceDeploymentUpdated 3m17s (x2 over 3m17s) pingsource-controller PingSource adapter deployment updated
Normal PingSourceSynchronized 3m17s pingsource-controller PingSource adapter is synchronized
After looking at this a bit more it appears that the name=value pairs you pass in to an event subscription prepend the string 'CE_' to the name.再看一遍之后,您传递给事件订阅的名称=值对似乎将字符串“CE_”添加到名称前。
Therefore, to allow for this in the running job, you would need to prepend the environment variable in the job with the CE_
.因此,要在正在运行的作业中允许这样做,您需要在作业中使用
CE_
预先设置环境变量。 For example:例如:
When I create the jobdefinition I add the environment variable like this: CE_FOO=BAR
当我创建 jobdefinition 时,我添加了这样的环境变量:
CE_FOO=BAR
Then, when I create the event subscription, for the --ext
flag, I use the original suggestion: --ext FOO=BAR
然后,当我创建事件订阅时,对于
--ext
标志,我使用原始建议:-- --ext FOO=BAR
I believe since the FOO variable in the event subscription automatically gets the prepended CE_
to the FOO
variable it should work.我相信由于事件订阅中的 FOO 变量会自动将前置的
CE_
添加到FOO
变量中,因此它应该可以工作。
Please let me know if this does not work or I misunderstood you.如果这不起作用或我误解了你,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.