本文介绍了如何在Jenkins管道脚本中使用源命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将bash执行命令重写为Jenkins管道.旧代码就像

I recently rewrite bash execution command into Jenkins pipeline. The old code is like

...
source environment.sh
//Build
//Test
...

现在我使用管道脚本来包装命令,像这样

Now I use pipeline script to wrap the command, like this

sh '''
    ...
    source environment.sh
    //Build
    //Test
    ...
'''

但是,出现错误,如.../.jenkins/script.sh: line 9: source: environment.sh: file not found.当我尝试less environment.sh时,它会正确显示.所以我怀疑sh wrap中的source command有问题.

However, I got an error, as.../.jenkins/script.sh: line 9: source: environment.sh: file not found. When I try to less environment.sh, it display correctly. So I suspect something wrong with source command within sh wrap.

在使用管道之前,source environment.sh命令在shell执行中工作正常.因此源代码是安装在Jenkins服务器上的,似乎管道脚本不知道源代码命令是什么.

Before using pipeline, source environment.sh command is working fine in shell execution. So source is install at Jenkins server, it seems pipeline script don't know what is the source command.

我该如何在sh wrapd块中运行源命令?

How could I do to run source command within sh wrapped block?

推荐答案

source environment.sh替换为

. ./environment.sh

请注意,第一个点后有一个空格.

Please note there is a space after first dot.

这篇关于如何在Jenkins管道脚本中使用源命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 20:05