在我们的一个Jenkins作业中,签入到拉取请求中,我们依赖于Bitbucket的实现细节,即拉取请求合并提交,可以使用pull-requests/*/merge
访问它。
Bitbucket已删除对3路合并的支持,因此我们无法运行:
if (isPR(config.BRANCH)) {
echo 'In PR type commit'
PR_ID=parsePRId(config.BRANCH)
TARGET_COMMIT="pull-requests/$PR_ID/merge"
FROM_COMMIT="pull-requests/$PR_ID/from"
} else {
echo 'Non PR type commit'
TARGET_COMMIT=config.BRANCH
FROM_COMMIT=config.BRANCH
}
// Fetch hash of from commit for marking build status
sh "git fetch origin $FROM_COMMIT"
result.branch = config.BRANCH
result.fromCommitId = sh(returnStdout: true, script: "git rev-parse FETCH_HEAD").trim()
result.fromCommitIdShort = sh(returnStdout: true, script: "git rev-parse --short FETCH_HEAD").trim()
try {
// Checkout target commit
sh """
git fetch origin $TARGET_COMMIT && \
git checkout -f FETCH_HEAD
"""
result.targetCommitId = sh(returnStdout: true, script: "git rev-parse FETCH_HEAD").trim();
result.targetCommitIdShort = sh(returnStdout: true, script: "git rev-parse --short FETCH_HEAD").trim();
} catch (Exception err) {
result.targetCommitId = null
result.targetCommitIdShort = null
}
最终目标是 checkout pull请求,以便在monorepo中构建/部署微服务。
1条答案
按热度按时间iih3973s1#
我通过创建一个重 checkout 来解决这个问题。这仍然需要更好地测试。