Created
April 30, 2020 12:11
-
-
Save revmischa/0e3d464257a20b86eca79710635f99e3 to your computer and use it in GitHub Desktop.
Jenkins groovy routine to wait for apt lock before running commands.
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
/** | |
* Wait for apt lock to be free, then run command. | |
* @param aptArgs E.g. `install -y emacs xterm` | |
*/ | |
void call(String aptArgs) { | |
def timeout = 120 // wait for lock this long | |
def fileno = 1000 // unused file descriptor number | |
def lockfile = "/var/lib/dpkg/lock" | |
sh """ | |
/usr/bin/sudo bash -c "(flock --timeout $timeout $fileno; apt $aptArgs) $fileno> $lockfile" | |
""" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment