简体   繁体   English

如何从詹金斯运行sh脚本

[英]How to run sh script from jenkins

I need launch sh script from jenkins, it is simple, but my script change symlink for JAVA_HOME, in fact im switching between JDK versions using sh script. 我需要从jenkins启动sh脚本,这很简单,但是我的脚本更改了JAVA_HOME的符号链接,实际上,我使用sh脚本在JDK版本之间进行了切换。 It works when Im launching job without jenkins(job writen on bash), but it does not working under jenkins... Jenkins remember JAVA_HOME after start and use this path... how can I change JAVA_HOME from sh script under jenkins ? 当我在没有jenkins的情况下启动作业时,它可以工作(工作在bash上写),但是在jenkins下无法工作... Jenkins在启动后还记得JAVA_HOME并使用此路径...如何在jenkins下从sh脚本更改JAVA_HOME? may be from script invoke jenkins reload config if it's possible... thx for any help! 可能是从脚本中调用jenkins重新加载配置,如果有的话……寻求帮助!

Just try as below ; 只需尝试以下方法;

    public static void execShellCmd(String cmd) {  
        try {  
            Runtime runtime = Runtime.getRuntime();  
            Process process = runtime.exec(new String[] { "/bin/bash", "-c", cmd });  
            int exitValue = process.waitFor();  
            System.out.println("exit value: " + exitValue);  
            BufferedReader buf = new BufferedReader(new InputStreamReader(process.getInputStream()));  
            String line = "";  
            while ((line = buf.readLine()) != null) {  
                System.out.println("exec response: " + line);  
            }  
        } catch (Exception e) {  
            System.out.println(e);  
        }  
    }  

For more details : Shell Script Running with java 有关更多详细信息: 使用Java运行的Shell脚本

Problem solved!!! 问题解决了!!! soulution is simple, I have sh script that was launched in jenkins job like this: ./MY_SCRIPT.sh 解决方案很简单,我有在jenkins工作中启动的sh脚本,如下所示:./MY_SCRIPT.sh

And after that script launched under jenkins and I had problems with switching JAVA_HOME. 在詹金斯下启动该脚本后,我在切换JAVA_HOME时遇到了问题。

All is need to do launch script like this: sh MY_SCRIPT.sh and it will launched smt like from the system. 所有需要做的启动脚本是这样的:sh MY_SCRIPT.sh,它将像从系统一样启动smt。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM