简体   繁体   English

GIT - 从 Jenkins 获取文件夹的最后提交

[英]GIT - get last commit for folder from Jenkins

I need to get last commit hash for some folders during Jenkins build.我需要在 Jenkins 构建期间为某些文件夹获取最后一次提交 hash。

Locally I use for it this command我在本地使用这个命令

git log --no-merges -1 --pretty=format:%H --output=c:/Temp/com.itextpdf.lastCommit -- com.itextpdf

This works fine and correct commit is written into the file.这工作正常,并且正确的提交被写入文件。

During Jenkins build I'm using this groovy script在 Jenkins 构建期间,我正在使用这个 groovy 脚本

dir("${prj}")
{
    echo "Getting last commits in manually numbered plugins"
    manuallyNumberedPlugins.each{
       echo "plugin: $it"
       String output = "${TEST_TEMP_DIR}/${it}.lastCommit"
       bat script: "${gitTool} log --no-merges -1 --pretty=format:%%H --output=$output -- $it"
    }
    echo "Done"
}

which executes following command执行以下命令

D:\Jenkins\workspace\GX_Branch\java>D:\Apps\Git.2.21.0\bin\git.exe log --no-merges -1 --pretty=format:%H --output=D:\Jenkins\workspace\GX_Branch/tmp/com.itextpdf.lastCommit -- com.itextpdf

But latest commit to whole repository is written into the output file instead of last commit to com.itextpdf folder.但是对整个存储库的最新提交被写入 output 文件,而不是最后一次提交到 com.itextpdf 文件夹。

I've overlooked that we use shallow copy with only last revision.我忽略了我们只使用最后一次修订的浅拷贝。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM