Skip to content

Instantly share code, notes, and snippets.

@revmischa
Created April 30, 2020 12:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revmischa/0e3d464257a20b86eca79710635f99e3 to your computer and use it in GitHub Desktop.
Save revmischa/0e3d464257a20b86eca79710635f99e3 to your computer and use it in GitHub Desktop.
Jenkins groovy routine to wait for apt lock before running commands.
/**
* 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