Add methods for Gerrit CR upload
The patch adds git and gerrit methods to
upload CR to Gerrit using pipelines.
Git`s "commitGitChanges" method has been
modified to support "-- amend" option.
Change-Id: I6f61784d0edf956418b033aae2407f1f868d5067
Related-PROD: PROD-30632
diff --git a/src/com/mirantis/mk/Git.groovy b/src/com/mirantis/mk/Git.groovy
index 575fb80..d9006fa 100644
--- a/src/com/mirantis/mk/Git.groovy
+++ b/src/com/mirantis/mk/Git.groovy
@@ -100,13 +100,20 @@
* @param path Path to the git repository
* @param message A commit message
* @param global Use global config
+ * @param amend Whether to use "--amend" in commit command
*/
-def commitGitChanges(path, message, gitEmail='jenkins@localhost', gitName='jenkins-slave', global=false) {
+def commitGitChanges(path, message, gitEmail='jenkins@localhost', gitName='jenkins-slave', global=false, amend=false) {
def git_cmd
+ def gitOpts
def global_arg = ''
if (global) {
global_arg = '--global'
}
+ if (amend) {
+ gitOpts = '--amend'
+ } else {
+ gitOpts = ''
+ }
dir(path) {
sh "git config ${global_arg} user.email '${gitEmail}'"
sh "git config ${global_arg} user.name '${gitName}'"
@@ -116,14 +123,13 @@
returnStdout: true
).trim()
git_cmd = sh(
- script: "git commit -m '${message}'",
+ script: "git commit ${gitOpts} -m '${message}'",
returnStdout: true
).trim()
}
return git_cmd
}
-
/**
* Push git changes to remote repo
*
@@ -231,4 +237,5 @@
returnStdout: true
).trim()
return branchesList.tokenize('\n')
-}
\ No newline at end of file
+}
+