diff --git a/Jenkinsfile b/Jenkinsfile
index f322bcdd6e439a51305c4008eb0c1cd65824b23b..ed1497254978c4b8fa87fc729cd52c8ffeb8b7a1 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -151,16 +151,13 @@ if (buildOnlyList) {
       }
 }
 
-// SSH complains loudly if the current user is not in the user database, so fake that
-def withSshAgent(credentials, command) {
-  sshagent(credentials: [ credentials, ] ) {
-    sh(script: "${command}")
-  }
-}
-
 def uploadDirectory(source, target) {
-  withSshAgent(upload_credentials, "ssh -oStrictHostKeyChecking=no ${upload_host} mkdir -p ${upload_root}/${target}/")
-  withSshAgent(upload_credentials, "rsync -e 'ssh -oStrictHostKeyChecking=no' -aP ${source} ${upload_dest}/${target}/")
+  sshagent(credentials: [ upload_credentials, ] ) {
+    sh(script: """
+      ssh -oStrictHostKeyChecking=no ${upload_host} mkdir -p ${upload_root}/${target}/
+      rsync -e 'ssh -oStrictHostKeyChecking=no' -aP ${source} ${upload_dest}/${target}/
+      """)
+  }
 }
 
 def pushOstreeRepo(architecture, type, board) {
@@ -169,7 +166,8 @@ def pushOstreeRepo(architecture, type, board) {
 
   // push if the destination repository already exist, otherwise do a full repo upload
   // but use --ignore-existing to mitigate the chance of races
-  withSshAgent(upload_credentials, """
+  sshagent(credentials: [ upload_credentials, ] ) {
+    sh(script: """
     cd ${PIPELINE_VERSION}/${architecture}/${type}
     if ssh -oStrictHostKeyChecking=no ${upload_host} test -e ${upload_root}/${ostree_path}
     then
@@ -179,6 +177,7 @@ def pushOstreeRepo(architecture, type, board) {
       ssh -oStrictHostKeyChecking=no ${upload_host} mkdir -p ${upload_root}/${ostree_path}/
       rsync -e 'ssh -oStrictHostKeyChecking=no' --ignore-existing -aP ${repo} ${upload_dest}/${ostree_path}
     fi""")
+  }
 
   // Cleanup uploaded branch
   sh(script: """