Skip to content

Commit ac3fbeb

Browse files
docs(srv): how to run complex commands with Jobs and Secrets MTA-6354 (#5424)
* docs(srv): how to run complex commands with Jobs and Secrets MTA-6354 * docs(srv): update * docs(srv): update * docs(srv): update * docs(srv): update * docs(srv): update * Apply suggestions from code review Co-authored-by: Néda <[email protected]> * docs(srv): update --------- Co-authored-by: Néda <[email protected]>
1 parent e6973f4 commit ac3fbeb

File tree

5 files changed

+141
-0
lines changed

5 files changed

+141
-0
lines changed

macros/serverless-jobs/automate-resources-management.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import Requirements from '@macros/iam/requirements.mdx'
77

88
[Scaleway Serverless Jobs](/serverless-jobs/quickstart/) allows you to create and automate recurring tasks. This page shows how to create jobs to perform any operation available with the [Scaleway CLI](https://github.com/scaleway/scaleway-cli/blob/master/docs/commands/config.md) to automate the management of your Scaleway resources.
99

10+
<Message type="note">
11+
To automate complex commands, such as piped or `xargs` commands, refer to the [dedicated documentation](/serverless-jobs/how-to/execute-complex-commands/).
12+
</Message>
13+
1014
Serverless Jobs are perfectly adapted for these autonomous tasks, as we do not need autoscaling or exposure via a web server. Refer to the [documentation on differences between jobs, containers, and functions](/serverless-jobs/reference-content/difference-jobs-functions-containers/) for more information.
1115

1216
<Requirements />

menu/navigation.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4855,6 +4855,10 @@
48554855
"label": "Manage the scheduling of a job",
48564856
"slug": "manage-job-schedule"
48574857
},
4858+
{
4859+
"label": "Execute complex startup commands",
4860+
"slug": "execute-complex-commands"
4861+
},
48584862
{
48594863
"label": "Reference secrets in a job",
48604864
"slug": "reference-secret-in-job"
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
title: How to execute complex startup commands using Serverless Jobs
3+
description: Learn how to run complex commands at job run start and scripts using Scaleway Serverless Jobs and Secrets Manager.
4+
tags: run execute start serverless job scaleway script startup secret bash complex command pipe
5+
dates:
6+
validation: 2025-08-19
7+
posted: 2025-08-19
8+
---
9+
import Requirements from '@macros/iam/requirements.mdx'
10+
11+
Scaleway Serverless Jobs allows you to execute specific startup commands when running a job. Due to technical specifications, complex commands (e.g. piped commands, `xargs` commands) may fail occasionally, preventing jobs from running successfully.
12+
13+
You can bypass this limitation by passing complex commands and scripts to a Serverless Job via a [secret reference](/serverless-jobs/concepts/#secrets-reference). You can then inject this secret as a file in your job, and call it at startup to execute the commands it contains.
14+
15+
<Requirements />
16+
17+
- A Scaleway account logged into the [console](https://console.scaleway.com)
18+
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
19+
- Created a [Serverless Job](/serverless-jobs/how-to/create-job/)
20+
21+
## How to create a secret containing your command
22+
23+
1. Click **Secret Manager** in the **Security & Identity** section of the [Scaleway console](https://console.scaleway.com/) side menu.
24+
25+
2. In the **Region** drop-down, select the [region](/secret-manager/concepts/#region) in which you want to store your secret. Secrets cannot be moved from one region to another after creation.
26+
27+
3. Click **+ Create secret**.
28+
29+
4. Select **Import secret**, choose the **Opaque** secret type, then drag and drop your file to the dedicated area. The maximum file size for your secret is 64 KiB.
30+
<Message type="note">
31+
We recommend using a shell script (`.sh`) file containing your command. Refer to the [section below](#complex-commands-examples) for example commands.
32+
</Message>
33+
34+
5. Choose the **Scaleway-managed encryption key**, as it requires no configuration on your side.
35+
36+
6. Choose a [path](/secret-manager/concepts/#path) for your secret.
37+
38+
7. Enter a name for your secret, and, optionally, add a description and tags.
39+
40+
8. Click **Create secret** to confirm.
41+
42+
Your file can now be passed to your Serverless Job as a secret reference.
43+
44+
## Create a Serverless Job referencing your command as a secret
45+
46+
1. Click **Jobs** in the **Serverless** section of the side menu. The jobs page displays.
47+
48+
2. Click **Create job**. The job creation wizard displays.
49+
50+
3. Select the **external** container registry.
51+
52+
4. Enter the following image URL:
53+
```sh
54+
scaleway/cli:latest
55+
```
56+
57+
5. Enter a name, select the desired region, and choose the smallest **resources** available.
58+
59+
6. From the **Data** tab, add your command file as a [secrets reference](/serverless-functions/concepts/#secrets). Refer to the [dedicated documentation](/serverless-jobs/how-to/reference-secret-in-job/) on secrets for more information.
60+
61+
7. From the **Execution** tab, add the following startup command to call your file:
62+
```sh
63+
bash /complex_command.sh start
64+
```
65+
66+
8. Click **Create job** to finish.
67+
68+
You job is now ready to run.
69+
70+
## Complex commands examples
71+
72+
Below are examples of commands that must be passed via a secret referenced as a file in Serverless Jobs. You can find more complex command examples on the [Scaleway CLI repository](/https://github.com/scaleway/scaleway-cli/blob/master/docs/cookbook.md).
73+
74+
**Retrieve a specific field from the output using jq**
75+
76+
```bash
77+
## Retrieve all available instance type names
78+
79+
# Using jq
80+
scw -o json instance server-type list | jq -r '.[].name'
81+
# Using CLI templates
82+
scw instance server-type list -o template="{{ .Name }}"
83+
```
84+
85+
**Filter command output using jq**
86+
87+
```bash
88+
# Retrieve all available instance type with GPUs
89+
scw -o json instance server-type list | jq '.[] | select (.gpu > 0)'
90+
```
91+
92+
**Parallelize actions using xargs**
93+
94+
```bash
95+
## Reboot all listed servers at the same time, 8 max concurrent actions
96+
97+
# Using jq
98+
scw -o json instance server list | jq -r '.[].id' | xargs -L1 -P8 scw instance server reboot
99+
# Using CLI templates
100+
scw instance server list -o template="{{ .ID }}" | xargs -L1 -P8 scw instance server reboot
101+
```
102+
103+
**Create arguments for a CLI command and use it in xargs**
104+
105+
```bash
106+
## List private-nics of all listed servers
107+
108+
# Using jq
109+
scw -o json instance server list | jq -r '.[] | "server-id=\(.id)"' | xargs -L1 scw instance private-nic list
110+
# Using CLI templates
111+
scw instance server list -o template="server-id={{ .ID }}" | xargs -L1 scw instance private-nic list
112+
```

pages/serverless-jobs/troubleshooting/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ productIcon: ServerlessJobsProductIcon
5252
- [My Job run is in an error state](/serverless-jobs/troubleshooting/job-in-error-state)
5353
- [Missing metrics for my Job Run](/serverless-jobs/troubleshooting/missing-metrics)
5454
</LinksList>
55+
- [Job startup command fails](/serverless-jobs/troubleshooting/job-startup-command-fails/)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: My job run fails when executing the startup command
3+
description: Troubleshoot job run failures due to startup commands for your Scaleway Serverless Jobs.
4+
tags: serverless jobs troubleshooting issue error state message fail execution log faliure does not run command
5+
dates:
6+
validation: 2025-08-20
7+
posted: 2025-08-20
8+
---
9+
10+
## Problem
11+
12+
My job run fails due to its startup command.
13+
14+
## Cause
15+
16+
Complex commands, such as piped or `xargs` commands may lead to failures due to techical limitations of Serverless Jobs.
17+
18+
## Possible solutions
19+
20+
You can bypass this issue by using [Secret Manager](/secret-manager/) to pass complex commands in a shell script file via a [secret reference](/serverless-jobs/concepts/secrets-references). Refer to the [dedicated documentation](/serverless-jobs/how-to/execute-complex-commands/) for more information

0 commit comments

Comments
 (0)