我想通过以下方式获得sh结果的输出:
* installing *source* package ‘quantreg’ ...
** package ‘quantreg’ successfully unpacked and MD5 sums checked
** libs
/Users/*/.R/Makevars:2: *** missing separator. Stop.
ERROR: compilation failed for package ‘quantreg’
* removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/quantreg’
* installing *source* package ‘mclust’ ...
** package ‘mclust’ successfully unpacked and MD5 sums checked
** libs
/Users/*/.R/Makevars:2: *** missing separator. Stop.
ERROR: compilation failed for package ‘mclust’
* removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/mclust’
ERROR: dependencies ‘pbkrtest’, ‘quantreg’ are not available for package ‘car’
* removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/car’
ERROR: dependency ‘car’ is not available for package ‘rstatix’
* removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rstatix’
ERROR: dependency ‘rstatix’ is not available for package ‘ggpubr’
* removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/ggpubr’
ERROR: dependency ‘ggpubr’ is not available for package ‘factoextra’
* removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/factoextra’
然后它向我显示错误:
‘/private/var/folders/8v/mfj4t9t54y72cdrz6q84jnjh0000gn/T/RtmpfEwO54/downloaded_packages’
完成:失败
如果使用传统的脚本方式,则效果很好。
1: In install.packages("factoextra", dependencies = TRUE) :
installation of package ‘quantreg’ had non-zero exit status
2: In install.packages("factoextra", dependencies = TRUE) :
installation of package ‘mclust’ had non-zero exit status
3: In install.packages("factoextra", dependencies = TRUE) :
installation of package ‘car’ had non-zero exit status
4: In install.packages("factoextra", dependencies = TRUE) :
installation of package ‘rstatix’ had non-zero exit status
5: In install.packages("factoextra", dependencies = TRUE) :
installation of package ‘ggpubr’ had non-zero exit status
6: In install.packages("factoextra", dependencies = TRUE) :
installation of package ‘factoextra’ had non-zero exit status
答案 0 :(得分:3)
由于您正在将方法调用的返回值分配给变量,因此现在已编写脚本,并且您需要将步骤封装在声明性DSL的script
块中:
pipeline {
agent any
stages {
stage('Hello') {
steps {
echo 'Hello World'
script {
result=sh(script:'ls -al', returnStdout: true)
}
}
}
}
}
答案 1 :(得分:0)
shell命令必须在声明性管道的sh块内运行。
例如:
pipeline {
agent any
stages {
stage('Hello') {
steps {
sh 'echo "Hello World"'
result=sh(script:'ls -al', returnStdout: true)
}
}
}
}
您也可以参考https://www.jenkins.io/doc/pipeline/tour/running-multiple-steps/了解更多信息。
答案 2 :(得分:0)
做这样的事情
pipeline {
agent any
stages {
stage('Hello') {
steps {
sh 'echo Hello World'
scripts {
result = sh(script:'ls -al', returnStdout: true)
}
}
}
}
}