且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Jenkins管道中生成自定义GitSCM变更日志

更新时间:2023-02-07 12:57:11

我不是很了解您的问题,但是Pipeline不支持使用Java File API,它将无法按预期运行.

I didn't really understand your question, but using the Java File API is not supported in Pipeline — it will not behave as you expect.

您实际上也应该避免直接写入$JENKINS_HOME目录-将文件写入构建工作区,然后使用archiveArtifacts步骤以确保将其存储在Jenkins主数据库中.

You really should avoid writing directly into the $JENKINS_HOME directory as well — write a file to the build workspace, then use the archiveArtifacts step to ensure that it gets stored on the Jenkins master.

您可以使用 writeFile步骤,例如:

You can do this using the writeFile step, e.g.:

def changelog = sh returnStdout: true, script: "git log …"
writeFile file: 'changelog0.xml', text: changelog
archiveArtifacts 'changelog0.xml'

还请注意,您应该在同一node('docker')块中同时运行checkoutgit log步骤(尽管它们仍然可以在node内部位于单独的stage块中).否则,不能保证在两种情况下都将获得相同的工作空间,因此,当您调用git log时,您可能最终会进入一个空的或过时的工作空间.

Note also that you should run both the checkout and the git log steps in the same node('docker') block (they can still be in separate stage blocks though, inside the node). Otherwise, it's not guaranteed that you'll get the same workspace in both cases, and so when you call git log, you may end up in an empty or outdated workspace.