如何在 Jenkins 流水线脚本中使用源命令 [英] How to use source command within Jenkins pipeline script

查看:39
本文介绍了如何在 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 包装块中运行 source 命令?

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 流水线脚本中使用源命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆