我目前正在努力运行要尝试从 Jenkins 触发的.sh
脚本。
在 Jenkins “执行外壳”部分中,我正在连接到远程服务器( Jenkins 代理没有正确的操作系统来构建所需的操作系统。) ,使用:
cp -r . /to/shared/drive/to/have/access/on/remote
ssh -t -t username@servername << EOF
cd /to/shared/drive/to/have/access/on/remote
source build.sh dev
exit
EOF
在build.sh
内部,我正在导出R_LIBS
来为不同的 R 版本构建软件包。
...
for path in "${!rVersionPaths[@]}"; do
export R_LIBS="${path}"
Rscript -e 'install.packages(c("someDependency", "someOtherDependency"), repos="http://cran.r-project.org");'
...
此处设置R_LIBS
的功能类似于在lib
中设置install.packages(...)
。由于某些原因,R_LIBS
export
未被使用。同样设置其他环境变量,例如http_proxy
也会被忽略。这会导致网络外部的任何请求失败。
有没有实现这一目标的特殊方法?
答案 0 :(得分:1)
也许可以通过env传递这些变量,例如
env R_LIBS="${path}" Rscript -e 'install.packages(c("someDependency", .....
答案 1 :(得分:0)
好吧,我无法对此问题发表评论,因此请将其发布为答案。
从Jenkins调用远程shell脚本时,我遇到了类似的问题,问题是从Jenkins调用脚本时,以某种方式未加载bash_profile变量,但在本地它起作用。在ssh连接中加载bash配置文件为我解决了该问题。
将源代码添加到build.sh中的bash_profile
. ~/.bash_profile
或source ~/.bash_profile
或 在SSH连接中重新加载bash_profile
`ssh -t -t username@servername << EOF
. ~/.bash_profile
your commands here
exit
EOF
答案 2 :(得分:0)
您可以在同一命令行中设置该变量,如下所示:
R_LIBS="${path}" Rscript -e \
'install.packages(c("someDependency", "someOtherDependency"), repos="http://cran.r-project.org");'
可以通过这种方式附加更多变量。请注意,这只会为在它们之后被调用的命令(以及它的子进程)设置那些环境变量。
答案 3 :(得分:0)
您说“ R_LIBS
export
未被捡起”。 问题值是UNSET吗?还是将其设置为其他值,而您正在尝试覆盖它?
SSH可能正在调用“ / bin / sh -c”。根据第二个答案:Why does 'cd' command not work via SSH?,您可以简化SSH命令并在Bash中显式调用build.sh脚本:
cp -r . /to/shared/drive/to/have/access/on/remote
ssh -t -t username@servername "cd /to/shared/drive/to/have/access/on/remote && bash -f build.sh dev"
这使SSH调用与在远程交互式Shell中调用命令更加相似。 (您可以避免采购脚本和导出变量。)
如果可以在任何命令前加上局部环境变量覆盖(与Luis的回答一致),则无需export R_LIBS
或env R_LIBS
:
...
for path in "${!rVersionPaths[@]}"; do
R_LIBS="${path}" Rscript -e 'install.packages(c("someDependency", "someOtherDependency"), repos="http://cran.r-project.org");'
...
Rscript
可能在env var方面做了很多工作。您可以通过用R_LIBS
命令替换Rscript
来验证您正在设置env
环境变量,并观察输出:
...
for path in "${!rVersionPaths[@]}"; do
R_LIBS="${path}" env
...
根据本手册“ Initialization at Start of an R Session”,Rscript
会在多个位置加载“站点和用户文件”:
该手册的“示例”部分显示了以下内容:
## Not run:
## Example ~/.Renviron on Unix
R_LIBS=~/R/library
PAGER=/usr/local/bin/less
如果您添加--vanilla
命令行选项来忽略所有这些文件,那么您可能会得到不同的结果,并且知道site / init / environ文件中的某些内容正在影响您的R_LIBS
!我自己无法运行此系统。希望我们能给您一些方面进行调查。
答案 4 :(得分:0)
您可能不想from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
,只需直接调用它即可(即删除source build.sh
命令)。
通过source
-写入文件,您的脚本将在SSH Shell中执行(可能是source
),而不是由sh
执行,这听起来像是您想要的。