Add terminating an SSH agent on logout
Enable ssh-agent process to be terminated automatically
on SI jenkins master, as SI pipelines run a lot of
ssh-agents and don't stop them at the moment.
Change-Id: Ieaee7f55f8dd0da1afa612bd08778f1500955f4a
Closes-PROD: PROD-31300
diff --git a/jobs/pipelines/swarm-create-cfg-config-drive.groovy b/jobs/pipelines/swarm-create-cfg-config-drive.groovy
index 10d0e5d..a8dd0ea 100644
--- a/jobs/pipelines/swarm-create-cfg-config-drive.groovy
+++ b/jobs/pipelines/swarm-create-cfg-config-drive.groovy
@@ -6,6 +6,7 @@
def common_scripts_commit = "${COMMON_SCRIPTS_COMMIT}"
def iso_name = "${CONFIG_DRIVE_ISO_NAME}" ?: "cfg01.${CLUSTER_NAME}-config-${dateFormat.format(date)}.iso"
def node_name = "${NODE_NAME}"
+def ssh = new com.mirantis.mk.Ssh()
def smc = [:]
smc['SALT_MASTER_MINION_ID'] = "cfg01.${CLUSTER_NAME}.local"
@@ -43,15 +44,17 @@
credentialsId: env.GERRIT_MCP_CREDENTIALS_ID,
usernameVariable: "GERRIT_USERNAME",
passwordVariable: "GERRIT_PASSWORD"]]) {
+ def gerrit_user = env.GERRIT_USERNAME
+ def gerrit_password = env.GERRIT_PASSWORD
+ String gerrit_host = "gerrit.mcp.mirantis.net"
+ String gerrit_port = "29418"
+ ssh.prepareSshAgentKey(env.GERRIT_MCP_CREDENTIALS_ID)
- sh ("""\
- set -ex
- eval \$(ssh-agent)
- ssh-add ${GERRIT_KEY}
- git clone ssh://${GERRIT_USERNAME}@gerrit.mcp.mirantis.net:29418/mcp/mcp-common-scripts mcp-common-scripts-git
- git clone --mirror ssh://${GERRIT_USERNAME}@gerrit.mcp.mirantis.net:29418/mk/mk-pipelines mk-pipelines
- git clone --mirror ssh://${GERRIT_USERNAME}@gerrit.mcp.mirantis.net:29418/mcp-ci/pipeline-library pipeline-library
- """)
+ ssh.agentSh(
+ "set -ex; " +
+ "git clone ssh://${gerrit_user}@${gerrit_host}:${gerrit_port}/mcp/mcp-common-scripts mcp-common-scripts-git; " +
+ "git clone --mirror ssh://${gerrit_user}@${gerrit_host}:${gerrit_port}/mk/mk-pipelines mk-pipelines; " +
+ "git clone --mirror ssh://${gerrit_user}@${gerrit_host}:${gerrit_port}/mcp-ci/pipeline-library pipeline-library")
if (COMMON_SCRIPTS_COMMIT != '') {
sh ("""\
@@ -63,42 +66,31 @@
}
if (MCP_COMMON_SCRIPTS_REFS != '') {
- sh ("""\
- set -ex
- eval \$(ssh-agent)
- ssh-add ${GERRIT_KEY}
- cd mcp-common-scripts-git
- git fetch https://gerrit.mcp.mirantis.com/mcp/mcp-common-scripts ${MCP_COMMON_SCRIPTS_REFS} && git checkout FETCH_HEAD
- git log -1
- """)
+ ssh.agentSh(
+ "set -ex; " +
+ "cd mcp-common-scripts-git; " +
+ "git fetch https://${gerrit_host}/mcp/mcp-common-scripts ${MCP_COMMON_SCRIPTS_REFS} && git checkout FETCH_HEAD; " +
+ "git log -1")
}
if (PIPELINE_LIBRARY_REF != '') {
- sh ("""\
- set -ex
- eval \$(ssh-agent)
- ssh-add ${GERRIT_KEY}
- cd pipeline-library
- git fetch https://gerrit.mcp.mirantis.net/mcp-ci/pipeline-library ${PIPELINE_LIBRARY_REF}
- git tag ${MCP_VERSION} FETCH_HEAD -f
- git branch -f release/${MCP_VERSION} FETCH_HEAD
- git log -1
- """)
+ ssh.agentSh(
+ "set -ex; " +
+ "cd pipeline-library; " +
+ "git fetch https://${gerrit_host}/mcp-ci/pipeline-library ${PIPELINE_LIBRARY_REF}; " +
+ "git tag ${MCP_VERSION} FETCH_HEAD -f; " +
+ "git branch -f release/${MCP_VERSION} FETCH_HEAD; " +
+ "git log -1")
}
if (MK_PIPELINES_REF != '') {
- sh ("""\
- set -ex
- eval \$(ssh-agent)
- ssh-add ${GERRIT_KEY}
- cd mk-pipelines
- git fetch https://gerrit.mcp.mirantis.net/mk/mk-pipelines ${MK_PIPELINES_REF}
- git tag ${MCP_VERSION} FETCH_HEAD -f
- git branch -f release/${MCP_VERSION} FETCH_HEAD
- git log -1
- """)
+ ssh.agentSh(
+ "set -ex; " +
+ "cd mk-pipelines; " +
+ "git fetch https://${gerrit_host}/mk/mk-pipelines ${MK_PIPELINES_REF}; " +
+ "git tag ${MCP_VERSION} FETCH_HEAD -f; " +
+ "git branch -f release/${MCP_VERSION} FETCH_HEAD; " +
+ "git log -1")
}
-
-
}
}