Last active
September 15, 2022 12:20
-
-
Save darkobits/edb29cf84e64d442cbf5d50832956860 to your computer and use it in GitHub Desktop.
Jenkins Interactive Shell
This file contains 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
script { | |
while (true) { | |
def cmd = input(message: 'Jenkins Interactive Shell', parameters: [ | |
string(name: 'cmd', description: 'Enter a command or leave blank to continue job.', defaultValue: '') | |
], ok: 'Execute') | |
if (cmd == '') { print 'Continuing job...'; break; } | |
try { sh cmd } catch (err) { } | |
} | |
} |
Very nice!
The Jenkins Pipeline Utilities library by ebay provides steps similar to this one, mainly:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will pause a job and present the user with an input field they can use to execute shell commands from the same context as the job itself, which is not only more convenient than SSH-ing into the Jenkins node, but also ensures that the environment is exactly the same as the one used by the executor.
Using in Declarative Pipelines
This snippet can be dropped into a Delcarative Pipeline between any other instructions in a
steps
block to pause the job at that point.Example