Import gpg only when needed
Change-Id: I8c45968b4749aa8d8248224f7dca5a9fa34bc168
diff --git a/src/com/mirantis/mk/Debian.groovy b/src/com/mirantis/mk/Debian.groovy
index 134dc9e..f0f4ba0 100644
--- a/src/com/mirantis/mk/Debian.groovy
+++ b/src/com/mirantis/mk/Debian.groovy
@@ -163,8 +163,12 @@
def workspace = common.getWorkspace()
def privKey = common.getCredentials(privateKeyCredId, "key")
def private_key = privKey.privateKeySource.privateKey
- writeFile file:"${workspace}/private.key", text: private_key
- sh(script: "gpg --no-tty --allow-secret-key-import --homedir ${workspace}/.gnupg --import ./private.key")
+ def gpg_key_id = common.getCredentials(privateKeyCredId, "key").username
+ def retval = sh(script: "export GNUPGHOME=${workspace}/.gnupg; gpg --list-secret-keys | grep ${gpg_key_id}", returnStatus: true)
+ if (retval) {
+ writeFile file:"${workspace}/private.key", text: private_key
+ sh(script: "gpg --no-tty --allow-secret-key-import --homedir ${workspace}/.gnupg --import ./private.key")
+ }
}
/*