-
Notifications
You must be signed in to change notification settings - Fork 258
docs(srv): how to run complex commands with Jobs and Secrets MTA-6354 #5424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1306947
docs(srv): how to run complex commands with Jobs and Secrets MTA-6354
SamyOubouaziz 1e51b88
docs(srv): update
SamyOubouaziz b633b33
docs(srv): update
SamyOubouaziz dc07414
docs(srv): update
SamyOubouaziz 787ad90
docs(srv): update
SamyOubouaziz d8aa8df
docs(srv): update
SamyOubouaziz 0a5d93d
Apply suggestions from code review
SamyOubouaziz 11733b8
docs(srv): update
SamyOubouaziz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
pages/serverless-jobs/how-to/execute-complex-commands.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| --- | ||
| title: How to execute complex startup commands using Serverless Jobs | ||
| description: Learn how to run complex commands at job run start and scripts using Scaleway Serverless Jobs and Secrets Manager. | ||
| tags: run execute start serverless job scaleway script startup secret bash complex command pipe | ||
| dates: | ||
| validation: 2025-08-19 | ||
| posted: 2025-08-19 | ||
| --- | ||
| import Requirements from '@macros/iam/requirements.mdx' | ||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| <Requirements /> | ||
|
|
||
| - A Scaleway account logged into the [console](https://console.scaleway.com) | ||
| - [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization | ||
| - Created a [Serverless Job](/serverless-jobs/how-to/create-job/) | ||
|
|
||
| ## How to create a secret containing your command | ||
|
|
||
| 1. Click **Secret Manager** in the **Security & Identity** section of the [Scaleway console](https://console.scaleway.com/) side menu. | ||
|
|
||
| 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. | ||
|
|
||
| 3. Click **+ Create secret**. | ||
|
|
||
| 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. | ||
| <Message type="note"> | ||
| We recommend using a shell script (`.sh`) file containing your command. Refer to the [section below](#complex-commands-examples) for example commands. | ||
| </Message> | ||
|
|
||
| 5. Choose the **Scaleway-managed encryption key**, as it requires no configuration on your side. | ||
|
|
||
| 6. Choose a [path](/secret-manager/concepts/#path) for your secret. | ||
|
|
||
| 7. Enter a name for your secret, and, optionally, add a description and tags. | ||
|
|
||
| 8. Click **Create secret** to confirm. | ||
|
|
||
| Your file can now be passed to your Serverless Job as a secret reference. | ||
|
|
||
| ## Create a Serverless Job referencing your command as a secret | ||
|
|
||
| 1. Click **Jobs** in the **Serverless** section of the side menu. The jobs page displays. | ||
|
|
||
| 2. Click **Create job**. The job creation wizard displays. | ||
|
|
||
| 3. Select the **external** container registry. | ||
|
|
||
| 4. Enter the following image URL: | ||
| ```sh | ||
| scaleway/cli:latest | ||
| ``` | ||
|
|
||
| 5. Enter a name, select the desired region, and choose the smallest **resources** available. | ||
|
|
||
| 6. Enter a CRON schedule to run your job periodically. Refer to the [dedicated documentation](/serverless-jobs/reference-content/cron-schedules/) on CRON schedules. | ||
|
|
||
| 7. From the **Data** tab, add your command file as a [secrets reference](/serverless-functions/concepts/#secrets). Refer to the [dedicated documentation] on secrets for more information. | ||
SamyOubouaziz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 8. From the **Execution** tab, add the following startup command to call your file: | ||
| ```sh | ||
| bash /complex_command.sh start | ||
| ``` | ||
|
|
||
| 9. Click **Create job** to finish. | ||
|
|
||
| You job is now ready to run at the specified schedule. | ||
SamyOubouaziz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Complex commands examples | ||
|
|
||
| Below are examples of commands that must be passed via a secret referenced as a file in Serverless Jobs. You can find more complex commands examples on the [Scaleway CLI repository](/https://github.com/scaleway/scaleway-cli/blob/master/docs/cookbook.md). | ||
SamyOubouaziz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| **Retrieve a specific field from the output using jq** | ||
|
|
||
| ```bash | ||
| ## Retrieve all available instance type names | ||
|
|
||
| # Using jq | ||
| scw -o json instance server-type list | jq -r '.[].name' | ||
| # Using CLI templates | ||
| scw instance server-type list -o template="{{ .Name }}" | ||
| ``` | ||
|
|
||
| **Filter command output using jq** | ||
|
|
||
| ```bash | ||
| # Retrieve all available instance type with GPUs | ||
| scw -o json instance server-type list | jq '.[] | select (.gpu > 0)' | ||
| ``` | ||
|
|
||
| **Parallelize actions using xargs** | ||
|
|
||
| ```bash | ||
| ## Reboot all listed servers at the same time, 8 max concurrent actions | ||
|
|
||
| # Using jq | ||
| scw -o json instance server list | jq -r '.[].id' | xargs -L1 -P8 scw instance server reboot | ||
| # Using CLI templates | ||
| scw instance server list -o template="{{ .ID }}" | xargs -L1 -P8 scw instance server reboot | ||
| ``` | ||
|
|
||
| **Create arguments for a CLI command and use it in xargs** | ||
|
|
||
| ```bash | ||
| ## List private-nics of all listed servers | ||
|
|
||
| # Using jq | ||
| scw -o json instance server list | jq -r '.[] | "server-id=\(.id)"' | xargs -L1 scw instance private-nic list | ||
| # Using CLI templates | ||
| scw instance server list -o template="server-id={{ .ID }}" | xargs -L1 scw instance private-nic list | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
pages/serverless-jobs/troubleshooting/job-startup-command-fails.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| --- | ||
| title: My job run fails when executing the startup command | ||
| description: Troubleshoot job run failures due to startup commands for your Scaleway Serverless Jobs. | ||
| tags: serverless jobs troubleshooting issue error state message fail execution log faliure does not run command | ||
| dates: | ||
| validation: 2025-08-20 | ||
| posted: 2025-08-20 | ||
| --- | ||
|
|
||
| ## Problem | ||
|
|
||
| My job run fails due to its startup command. | ||
|
|
||
| ## Cause | ||
|
|
||
| Complex commands, such as piped or `xargs` commands may lead to failures due to techical limitations of Serverless Jobs. | ||
|
|
||
| ## Possible solutions | ||
|
|
||
| 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.