我想在 jenkins 中使用来自 git 的以下管道脚本
#!groovy
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building..'
}
}
stage('Test') {
steps {
echo 'Testing..'
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
}
}
}
}
我正确设置了存储库 URL,在“其他行为”下添加了“ checkout 到子目录”并将我的子目录写在那里。
在“脚本路径”我写了:mysubdirectory/Jenkinsfile
当我尝试运行它时出现以下错误:
java.io.FileNotFoundException
at jenkins.plugins.git.GitSCMFile$3.invoke(GitSCMFile.java:167)
at jenkins.plugins.git.GitSCMFile$3.invoke(GitSCMFile.java:159)
at jenkins.plugins.git.GitSCMFileSystem$3.invoke(GitSCMFileSystem.java:162)
at org.jenkinsci.plugins.gitclient.AbstractGitAPIImpl.withRepository(AbstractGitAPIImpl.java:29)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.withRepository(CliGitAPIImpl.java:71)
at jenkins.plugins.git.GitSCMFileSystem.invoke(GitSCMFileSystem.java:158)
at jenkins.plugins.git.GitSCMFile.content(GitSCMFile.java:159)
at jenkins.scm.api.SCMFile.contentAsString(SCMFile.java:338)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:101)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:59)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:262)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:415)
Finished: FAILURE
我做错了什么?
如何从 git 正确运行 Jenkins 脚本?
最佳答案
要从 Git 存储库成功运行 Jenkinsfile,Jenkinsfile 应该在主目录路径中可用,但不在子目录中。 例如:
.
├── .setting
├── project
└── Jenkinsfile
Jenkinsfile 不应该在子目录中。
关于git - 使用来自 Git 的代码运行 Jenkins 流水线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46277936/