美文网首页
基于Jenkins的cicd配置问题汇总

基于Jenkins的cicd配置问题汇总

作者: 倔强_2722 | 来源:发表于2021-12-23 16:45 被阅读0次

    按照https://www.codenong.com/cs106759370/教程进行cicd配置;

    发现问题:
    1.配置完成后提交测试代码,Jenkins并没有自动触发任何构建job?


    image.png

    我使用的是ngrok进行内网穿透,这个工具对webhook的请求都做了响应,但是都处理成forbidden,无法正常访问到本地localhost:8080,所以未正常触发持续集成操作。

    --forbidden为什么会返回403,待查后补充。。。

    1. 第一次构建提示
    <pre class="console-output" style="box-sizing: inherit; white-space: pre-wrap; overflow-wrap: break-word; margin: 0px; font-size: var(--font-size-monospace);">ERROR: Error cloning remote repo 'origin'
    hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- [https://github.com/xxxxxxxxxx/JenkinsCicd.git](https://github.com/xxxxxxxx/JenkinsCicd.git) +refs/heads/*:refs/remotes/origin/*" returned status code 128:
    stdout: 
    stderr: error: RPC failed; curl 7 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 60
    fatal: the remote end hung up unexpectedly
    
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2681)
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2102)
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:86)
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:624)
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:853)
        at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1224)
        at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1302)
        at hudson.scm.SCM.checkout(SCM.java:537)
        at hudson.model.AbstractProject.checkout(AbstractProject.java:1213)
        at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:643)
        at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:85)
        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:515)
        at hudson.model.Run.execute(Run.java:1891)
        at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)
        at hudson.model.ResourceController.execute(ResourceController.java:99)
        at hudson.model.Executor.run(Executor.java:440)
    ERROR: Error cloning remote repo 'origin'
    Finished: FAILURE
    </pre>
    

    解决方法:公司网络慢因此设置git配置参数,否则因此超时退出

    $ git config --global http.lowSpeedLimit 0
    
    $ git config --global http.lowSpeedTime 999999
    
    $ git config --global http.postBuffer 5242880
    

    3.第二次构建提示

    <pre class="console-output" style="box-sizing: inherit; white-space: pre-wrap; overflow-wrap: break-word; margin: 0px; font-size: var(--font-size-monospace);">ERROR: Processing failed due to a bug in the code. Please report this to the issue tracker ([https://jenkins.io/redirect/report-an-issue](https://jenkins.io/redirect/report-an-issue)).
    java.lang.IllegalArgumentException: /usr/local/Cellar/maven/3.8.4 doesn't have a 'lib' subdirectory - thus cannot be a valid maven installation!
        at hudson.maven.MavenEmbedderUtils.buildClassRealm(MavenEmbedderUtils.java:85)
        at hudson.maven.MavenEmbedderUtils.getMavenVersion(MavenEmbedderUtils.java:194)
        at hudson.maven.MavenEmbedderUtils.getMavenVersion(MavenEmbedderUtils.java:185)
        at hudson.maven.MavenVersionCallable.call(MavenVersionCallable.java:69)
        at hudson.maven.MavenVersionCallable.call(MavenVersionCallable.java:41)
        at hudson.FilePath.act(FilePath.java:1260)
        at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:639)
        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:520)
        at hudson.model.Run.execute(Run.java:1891)
        at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)
        at hudson.model.ResourceController.execute(ResourceController.java:99)
        at hudson.model.Executor.run(Executor.java:440)
    project=hudson.maven.MavenModuleSet@208b27ab[jenkinsCICDtest]
    project.getModules()=[]
    project.getRootModule()=null
    FATAL: /usr/local/Cellar/maven/3.8.4 doesn't have a 'lib' subdirectory - thus cannot be a valid maven installation!
    java.lang.IllegalArgumentException: /usr/local/Cellar/maven/3.8.4 doesn't have a 'lib' subdirectory - thus cannot be a valid maven installation!
        at hudson.maven.MavenEmbedderUtils.buildClassRealm(MavenEmbedderUtils.java:85)
        at hudson.maven.MavenEmbedderUtils.getMavenVersion(MavenEmbedderUtils.java:194)
        at hudson.maven.MavenEmbedderUtils.getMavenVersion(MavenEmbedderUtils.java:185)
        at hudson.maven.MavenVersionCallable.call(MavenVersionCallable.java:69)
        at hudson.maven.MavenVersionCallable.call(MavenVersionCallable.java:41)
        at hudson.FilePath.act(FilePath.java:1260)
        at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:639)
        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:520)
        at hudson.model.Run.execute(Run.java:1891)
        at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)
        at hudson.model.ResourceController.execute(ResourceController.java:99)
        at hudson.model.Executor.run(Executor.java:440)
    Finished: FAILURE
    </pre>
    

    这个是我Jenkins上的maven_home配置错了,Mac应该是/usr/local/Cellar/maven/3.8.4/libexec,之前少了libexec目录

    4.第四次构建问题

    Parsing POMs
    ERROR: No such file /Users/xxxxxxxxx/.jenkins/workspace/jenkinsCICDtest/Jenkins/pom.xml
    Perhaps you need to specify the correct POM file path in the project configuration?
    Finished: FAILURE
    
    参考内容

    参考配置文档配置的build处为jenkins/pom.xml,而实际上我的pom文件在root目录下面,修改为原来的pom.xml路径即可

    5.项目里增加了module,在集成编译过程中失败,提示找不到包

    <pre class="console-output" style="box-sizing: inherit; white-space: pre-wrap; overflow-wrap: break-word; margin: 0px; font-size: var(--font-size-monospace); color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Chapter1: Compilation failure: Compilation failure: 
    [ERROR]/Users/xxxx/.jenkins/workspace/jenkinsCICDtest/Chapter1/src/main/java/com/httpclient/demo.java:[10,30] 程序包org.testng.annotations不存在
    [ERROR]/Users/xxxxxxx/.jenkins/workspace/jenkinsCICDtest/Chapter1/src/main/java/com/httpclient/demo.java:[16,6] 找不到符号
    [ERROR] 符号:   类 Test 
    [ERROR] 位置: 类 com.httpclient.demo 
    [ERROR] -> [Help 1] 
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
    [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles: 
    [ERROR] [Help 1][http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException](http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException) [ERROR] 
    </pre>
    

    原因是我在增加的module里面配置的testng依赖,scope处理的是test,而非compile,maven在编译时找不到testng依赖。

    将maven的pom.xml testng修改如下
          <dependency>
              <groupId>org.testng</groupId>
              <artifactId>testng</artifactId>
              <version>6.9.9</version>
              <scope>compile</scope>
    
          </dependency>
    
    
    scope的其他参数如下:
    
     
    
    compile
    默认的scope,表示 dependency 都可以在生命周期中使用。而且,这些dependencies 会传递到依赖的项目中。适用于所有阶段,会随着项目一起发布
    provided
    跟compile相似,但是表明了dependency 由JDK或者容器提供,例如Servlet AP和一些Java EE APIs。这个scope 只能作用在编译和测试时,同时没有传递性。
    runtime
    表示dependency不作用在编译时,但会作用在运行和测试时,如JDBC驱动,适用运行和测试阶段。
    test
    表示dependency作用在测试时,不作用在运行时。 只在测试时使用,用于编译和运行测试代码。不会随项目发布。
    system
    跟provided 相似,但是在系统中要以外部JAR包的形式提供,maven不会在repository查找它。
    转载于:https://www.cnblogs.com/Mr-xiao/p/5892752.html
    

    相关文章

      网友评论

          本文标题:基于Jenkins的cicd配置问题汇总

          本文链接:https://www.haomeiwen.com/subject/hodhqrtx.html