简体   繁体   English

IBM Cloud Code Engine:如何在 cron 调用的作业运行中覆盖环境变量?

[英]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.

相关问题 IBM Cloud Code Engine:如何从环境中确定应用程序 URL? - IBM Cloud Code Engine: How to determine app URL from environment? IBM Cloud Code Engine:当应用程序不活动时如何检查日志? - IBM Cloud Code Engine: How to check logs when app not active? IBM Cloud:如何将 Db2 Warehouse 绑定到 Code Engine 应用程序? - IBM Cloud: How to bind Db2 Warehouse to Code Engine app? 使用 Cloud Engine 时,在 IBM Cloud 中可访问作业的输出在哪里? - Where is the ouput of a Job accessible in IBM Cloud, when using Cloud Engine? 如何将自定义域添加到 IBM 云引擎 - How to add a custom domain to IBM cloud engine 尝试在IBM Cloud Functions中运行代码 - Trying to run code in IBM Cloud Functions 如何检查Openwhisk(IBM Cloud Functions)是否被调用? - How can I check that Openwhisk (IBM Cloud Functions) gets invoked? IBM Cloud Code Engine:如何在没有 CLI 的情况下从 GitLab 源部署应用程序 - IBM Cloud Code Engine: How can I deploy an app from GitLab source without CLI IBM Cloud:如何控制由 Code Engine 构建引起的容器镜像数量? - IBM Cloud: How to control number of container images caused by Code Engine builds? IBM Cloud:尝试创建 Code Engine 项目时出错 - IBM Cloud: Error trying to create Code Engine project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM