git - 使用来自 Git 的代码运行 Jenkins 流水线

标签 git jenkins groovy jenkins-plugins jenkins-pipeline

我想在 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/

相关文章:

eclipse - 使用 Eclipse EGit 在 1and1 共​​享 Linux 服务器中克隆 1and1 git 存储库时出现问题

ubuntu - 如何使用 docker SSH 进入正在运行的容器

grails - 有没有办法让Grails中的 Controller 之间可以访问功能?

groovy - groovy扩展运算符的Java翻译

java - 通过 Spock 测试应用参数约束

git - 了解 Git 和 GitHub 的基础知识

windows - sh.exe“:/bin/git bad file number when git -version

git - git 应该删除空目录吗?

android - 如何通过 Jenkins 中的构建数量设置 android 应用程序版本?

node.js - Jenkins 在 Windows Server 2012 上构建由于 node-gyp 失败,可从命令行运行