JetBrains Space Help

Run Shell Scripts

Using the shellScript keyword, you can run an arbitrary shell script. This could be a one-liner or a multiline script. The default script interpreter /bin/sh can be changed with interpreter.

For example:

job("Run shell script") { container(displayName = "Show work dir", image = "ubuntu") { shellScript { interpreter = "/bin/bash" // note that you should escape the $ symbol in a Kotlin way content = """ echo The working directory is echo ${'$'}JB_SPACE_WORK_DIR_PATH """ } } }

If you want to run an existing script file (e.g., stored in the project repository), you should specify its location. It could be an absolute path, or a path that is relative to a working directory. If your script file requires arguments, you can provide them with the args function.

job("Run shell script") { container(displayName = "Run myscript", image = "ubuntu") { shellScript { location = "./myscript.sh" args("arg1, arg2") } } }

Run a default image command

Alternatively to running a shell script, you can run a default image command. To run the default command, provide its arguments in the args array. Note that special characters must be escaped.

For example:

job("Example") { container(displayName = "Say Hello", image = "alpine") { args("echo", "Hello World!") } }

If you want to override the default image command, you can do this by using entrypoint. In this case, args provide arguments for the entrypoint command. Note that special characters must be escaped.

For example:

job("Example") { container(displayName = "Say Hello", image = "gradle:latest") { entrypoint("/bin/sh") args("echo", "Hello World!") } }

Last modified: 15 December 2023