码迷,mamicode.com
首页 > 其他好文 > 详细

Jenkins 配置任务中的坑s

时间:2017-06-28 21:47:48      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:one   led   use   class   sed   spec   new   文件   cal   

Jenkins

坑1:sh: adb: command not found

背景:在任务中使用了adb命令

adb 使用时要在服务器上配Android-home的环境变量的

配置完成之后发现在服务器上 adb OK,但是在jenkins 执行job时不OK

参考一下两篇文档

https://stackoverflow.com/questions/29216244/jenkins-build-failed-due-to-missing-android-sdk

http://www.linuxdiyf.com/linux/28771.html

 

1.在jenkins 设置里配置Android-home,然而并没有用

技术分享

2.在Execute shell 里将#!/bin/bash 改成 #!/bin/bash -ilex

实测是有用的~

3.实际挨个试了下#!/bin/bash -ilex中的各个参数 发现有用的是-l

‘‘‘

-l        Make bash act as if it had been invoked as a login shell (see

                 INVOCATION below).

 

When  bash is invoked as an interactive login shell, or as a non-inter-

       active shell with the --login option, it first reads and executes  com-

       mands  from  the file /etc/profile, if that file exists.  After reading

       that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,

       in  that order, and reads and executes commands from the first one that

       exists and is readable.  The --noprofile option may be  used  when  the

       shell is started to inhibit this behavior.

‘‘‘ 

 综上,就是加载了/etc/profile或者其他几个配置环境变量的文件

所以直接改成在 shell 脚本里增加source /etc/profile就好啦~

 

 

坑2 Jenkins + python 的任务,console output 没有及时输出日志

期初是以为是 #!/bin/bash -ilex 中四个参数导致console output 没有输出,后来突然意识到是python的print应该有buffer的问题

https://stackoverflow.com/questions/22826006/how-to-get-python-print-result-in-jenkins-console-output

https://stackoverflow.com/questions/11631951/jenkins-console-output-not-in-realtime

有两种解释

1.jenkins 要输入换行符才能展示数据

Any output to stdout from a process spawned by Jenkins should be captured by Console Output. One caveat is that it won‘t be displayed until a newline character is printed, so make sure your lines are terminated.

2.print有buffer

  • ruby or python or any sensible scripting language will buffer the output; this is in order to minimize the IO; writing to disk is slow, writing to a console is slow...
  • usually the data gets flush()‘ed automatically after you have enough data in the buffer with special handling for newlines. e.g. writing a string without newline then sleep() would not write anything until after the sleep() is complete (I‘m only using sleep as an example, feel free to substitute with any other expensive system call).

解决方法看到两个

1.print 信息后加sys.stdout.flush()

2.

  • for python, you can use python -u or the environment variable PYTHONUNBUFFERED to make stdin/stdout/stout not buffered, but there are other solutions that do not change stdin or stderr

    export PYTHONUNBUFFERED=1

Jenkins 配置任务中的坑s

标签:one   led   use   class   sed   spec   new   文件   cal   

原文地址:http://www.cnblogs.com/silvi/p/7091321.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!