脚本化管道 - Groovy 用于获取提交哈希或标记的语法
Scripted pipeline - Groovy syntax to grab commit hash or tag
对于 Dev/QA/Prod 管道,我们要通知用户管道正在选择哪个提交哈希。
这主要有助于 Prod 管道,然后再部署到生产中。
下面是用于从特定分支中选取最新提交的 groovy 语法。
git branch: branchName, credentialsId: credential, url: "${gitLabServer}/${projectName}/${repo}.git"
1)
如何从结帐中获取提交 hash/tag?
2)
如果特定分支不可用,如何抓取错误?
您可以使用 return TreeMap
从 git
:
获取信息
try {
d = git(branch: branchName, credentialsId: credential, url: "${gitLabServer}/${projectName}/${repo}.git")
echo d["GIT_COMMIT"]
} catch (Exception e) {
echo "${e}"
}
字段:
GIT_AUTHOR_EMAIL
GIT_AUTHOR_NAME
GIT_BRANCH
GIT_COMMIT
GIT_COMMITTER_EMAIL
GIT_COMMITTER_NAME
GIT_LOCAL_BRANCH
GIT_PREVIOUS_COMMIT
GIT_PREVIOUS_SUCCESSFUL_COMMIT
GIT_URL
更新:
def treeMapData
pipeline {
agent any
stages {
stage ('Get Commit') {
steps{
script{
try {
treeMapData = git(branch: branchName, credentialsId: credential, url: "${gitLabServer}/${projectName}/${repo}.git")
echo treeMapData["GIT_COMMIT"]
} catch (Exception e) {
echo "${e}"
}
}
}
}
}
}
或
def treeMapData
node {
stage ('Build') {
try {
treeMapData = git(branch: branchName, credentialsId: credential, url: "${gitLabServer}/${projectName}/${repo}.git")
echo treeMapData["GIT_COMMIT"]
} catch (Exception e) {
echo "${e}"
}
}
}
对于 Dev/QA/Prod 管道,我们要通知用户管道正在选择哪个提交哈希。
这主要有助于 Prod 管道,然后再部署到生产中。
下面是用于从特定分支中选取最新提交的 groovy 语法。
git branch: branchName, credentialsId: credential, url: "${gitLabServer}/${projectName}/${repo}.git"
1) 如何从结帐中获取提交 hash/tag?
2) 如果特定分支不可用,如何抓取错误?
您可以使用 return TreeMap
从 git
:
try {
d = git(branch: branchName, credentialsId: credential, url: "${gitLabServer}/${projectName}/${repo}.git")
echo d["GIT_COMMIT"]
} catch (Exception e) {
echo "${e}"
}
字段:
GIT_AUTHOR_EMAIL
GIT_AUTHOR_NAME
GIT_BRANCH
GIT_COMMIT
GIT_COMMITTER_EMAIL
GIT_COMMITTER_NAME
GIT_LOCAL_BRANCH
GIT_PREVIOUS_COMMIT
GIT_PREVIOUS_SUCCESSFUL_COMMIT
GIT_URL
更新:
def treeMapData
pipeline {
agent any
stages {
stage ('Get Commit') {
steps{
script{
try {
treeMapData = git(branch: branchName, credentialsId: credential, url: "${gitLabServer}/${projectName}/${repo}.git")
echo treeMapData["GIT_COMMIT"]
} catch (Exception e) {
echo "${e}"
}
}
}
}
}
}
或
def treeMapData
node {
stage ('Build') {
try {
treeMapData = git(branch: branchName, credentialsId: credential, url: "${gitLabServer}/${projectName}/${repo}.git")
echo treeMapData["GIT_COMMIT"]
} catch (Exception e) {
echo "${e}"
}
}
}