zoukankan      html  css  js  c++  java
  • Jenkins+github的一次定时构建示例

      首先说明,我的电脑环境是windows,所以以下的示例是基于windows10 X64。

    一、新建任务,填写名称,选择类型,点击左下角的【确定】

    二、配置

    1、General

    2、源码管理

      之前在github上配置了公钥(配置的东西看这里https://www.cnblogs.com/zichuan/p/9274785.html)这里要拉取github的代码,需要配置私钥,点击Add,弹窗中填写数据。

    3、构建触发器

      这里我用的是定时任务,一般项目也用的这个选项吧。

    4、构建环境

      这个模块默认即可,这个示例用不到

    5、构建

    6、构建后操作

      我这里设置的比较简单,就是发送邮件。

    三、查看构建的结果

      以上设置完成之后,点击【保存】,点击左边菜单栏的【立即构建】,可以查看构建的结果。

      以上,在整个示例过程中,我遇到了一个坑,说大不大,说小不小。我只能说,windows和Linux还是区别的,下面来说说这个坑的发生过程:

    1、我是windows环境,然后在构建的时候选择了执行shell脚本,然后改了很多地方,还是没解决,报错方式是这样的:

    [0716_test] $ sh -xe C:WINDOWSTEMPjenkins1910652898694296835.sh
    The system cannot find the file specified
    FATAL: 命令执行失败
    java.io.IOException: CreateProcess error=2, 系统找不到指定的文件。
        at java.lang.ProcessImpl.create(Native Method)
        at java.lang.ProcessImpl.<init>(Unknown Source)
        at java.lang.ProcessImpl.start(Unknown Source)
    Caused: java.io.IOException: Cannot run program "sh" (in directory "C:Program Files (x86)Jenkinsworkspace716_test"): CreateProcess error=2, 系统找不到指定的文件。
        at java.lang.ProcessBuilder.start(Unknown Source)
        at hudson.Proc$LocalProc.<init>(Proc.java:249)
        at hudson.Proc$LocalProc.<init>(Proc.java:218)
        at hudson.Launcher$LocalLauncher.launch(Launcher.java:929)
        at hudson.Launcher$ProcStarter.start(Launcher.java:449)
        at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:109)
        at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
        at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
        at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
        at hudson.model.Build$BuildExecution.build(Build.java:206)
        at hudson.model.Build$BuildExecution.doRun(Build.java:163)
        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
        at hudson.model.Run.execute(Run.java:1794)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
        at hudson.model.ResourceController.execute(ResourceController.java:97)
        at hudson.model.Executor.run(Executor.java:429)
    Build step '执行 shell' marked build as failure
    Finished: FAILURE

      找了我半个多小时,然后在这里找到了比较明确的说明以及解决方案:https://stackoverflow.com/questions/30374998/run-a-command-shell-in-jenkins。但是我试了添加系统环境变量和更改Jenkins的shell配置这两种方法都没成功,还是算了,老老实实选择“执行windows批处理命令”。有兴趣的看客可以试试,成功了给我留个言即可,在此谢过。

    补充:针对构建模块中的语句,此示例中是python xx.py,如果构建之后日志中提示“python不是内部或者外部命令”。请先在cmd中尝试执行python的命令(例python,回车。可以查看Python的版本)看是否成功。报错的原因是执行Jenkins的系统用户环境变量中没有python的环境变量,所以解决方法是:在系统环境变量path中添加python.exe这个文件的路径!

    ——日月盈昃,辰宿列张

  • 相关阅读:
    [2018福大至诚软工助教]原型设计+用户规格说明书小结
    高等数理逻辑大作业
    [2018福大至诚软工助教]测试与优化小结
    [2018福大至诚软工助教]结对项目小结
    BETA 版冲刺前准备
    Alpha冲刺之事后诸葛亮
    Alpha 冲刺 (10/10)
    Alpha 冲刺 (9/10)
    Alpha 冲刺 (8/10)
    Alpha 冲刺 (7/10)
  • 原文地址:https://www.cnblogs.com/zichuan/p/9318149.html
Copyright © 2011-2022 走看看