Creating a Script
Function
This API is used to create custom job scripts.
- A script with a tag attribute is a high-risk script. When creating such script, you do not need to perform secondary verification on whether it is high-risk.
- Tenants are isolated. For scripts created through the northbound interface, if the reviewer field is not set, review is not required by default.
- Constraints:
- Script name: The script name must be unique under the same tenant. The value can contain a maximum of 64 characters, including letters, digits, and underscores (_).
- The script content can contain a maximum of 4096 characters.
- A maximum of 20 script parameters are supported.
- Script description: Enter a maximum of 256 characters.
- The name of a single parameter can contains 64 characters, including only letters, digits, and underscores (_).
- The value of a single parameter can contain a maximum of 1024 characters. The regular expression is ^((?!.{2,})[a-zA-Z0-9_-/.*\x20?:",=+@\[{]}])*$.
- A maximum of five reviewers are supported.
- The maximum size of logs generated by the script can only be 1 MB.
URI
POST /v1/job/scripts
Request Parameters
Parameter |
Mandatory or Not |
Type |
Description |
---|---|---|---|
name |
Yes |
String |
Script name: The value can contain only letters, digits, and underscores (_). Minimum length: 1 character Maximum length: 64 characters |
properties |
Yes |
ScriptPropertiesModel object |
Label of the script.
|
description |
Yes |
String |
Script description Minimum length: 1 character Maximum length: 256 characters |
type |
Yes |
String |
Script type, which is distinguished by script name suffixes: SHELL:.sh PYTHON:.py BAT:.bat The value can be:
|
content |
Yes |
String |
Script content Minimum length: 1 character Maximum length: 4096 characters |
script_params |
No |
Array of ScriptParamDefine objects |
Input parameter Array length: 0 to 20 characters |
Parameter |
Mandatory or Not |
Type |
Description |
---|---|---|---|
risk_level |
Yes |
String |
Risk level. LOW: low risk. MEDIUM: medium risk. HIGH: high risk. The value can be:
|
version |
Yes |
String |
Script version number. Minimum length: 1 character Maximum length: 10 characters |
reviewers |
No |
Array of ReviewerInfo objects |
Approver. If this parameter is not specified, review is not required. Array length: 0 to 5 characters |
protocol |
No |
String |
Review message notification protocol, which is used to notify reviewers. DEFAULT: default; SMS: SMS; EMAIL: email; DING_TALK: DingTalk; WE_LINK: WeLink; WECHAT: WeChat; CALLNOTIFY: language; NOT_TO_NOTIFY: no notification The value can be:
|
Parameter |
Mandatory or Not |
Type |
Description |
---|---|---|---|
reviewer_name |
Yes |
String |
Reviewer name (IAM username) Minimum length: 1 character Maximum length: 64 characters |
reviewer_id |
Yes |
String |
Reviewer ID (IAM user ID) Minimum length: 0 character Maximum length: 32 characters |
Parameter |
Mandatory or Not |
Type |
Description |
---|---|---|---|
param_name |
Yes |
String |
The parameter name can contain only letters, digits, and underscores (_). Minimum length: 1 character Maximum length: 64 characters |
param_value |
Yes |
String |
Default value. Minimum length: 0 character Maximum length: 1,024 characters |
param_description |
Yes |
String |
Description of the parameter. Minimum length: 0 character Maximum length: 256 characters |
param_order |
Yes |
Integer |
Parameter sequence. The value starts from 1 and must be consecutive. Minimum value: 1 Maximum value: 20 |
sensitive |
Yes |
Boolean |
Whether a parameter is sensitive. |
Response Parameters
Status code: 400
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code Minimum length: 8 characters Maximum length: 36 characters |
error_msg |
String |
Error description Minimum length: 2 characters Maximum length: 512 characters |
Request Example
Instance Request Body
https://coc.myhuaweicloud.com/v1/job/scripts { "type" : "SHELL", "content" : "echo ${value}", "name" : "09101112", "description": " Instance Script", "properties" : { "risk_level" : "HIGH", "version" : "1.0.0", "reviewers" : [ { "reviewer_name" : "test", "reviewer_id" : "7a8513cd87b7448283a1d5190eb91234" } ], "protocol" : "WECHAT" }, "script_params" : [ { "param_name" : "a", "param_value" : "string", "param_description" : "string", "param_order" : 1, "sensitive" : true } ] }
Response Example
Status code: 200
Script UUID.
{ "data" : "SC2023102521413701c4a8a62" }
Status code: 400
Contains error information.
{ "error_code" : "COC.00040701", "error_msg" : "script_params size must be between 0 and 50" }
Status Code
Status Code |
Description |
---|---|
200 |
Script UUID. |
400 |
Contains error information. |
Error code
See Error code.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.