我创建了一个詹金斯管道。在此管道中,我启动了一个Docker容器,并希望在此启动的Docker容器中执行一些操作,但是出现以下错误:
java.io.IOException: Failed to run image 'grme/nightwatch-chrome-firefox:1.0.0'. Error: docker: Error response from daemon: the working directory 'C:\Jenkins\workspace\FirstTest' is invalid, it needs to be an absolute path.
我的本地Jenkins服务器正在我的本地Windows 10和Docker上运行,我已经在我的机器上安装了它。我能够提取特定的Docker映像,并且能够通过docker run
执行cmd
命令。
在另一个基于Unix的Jenkins服务器中,我没有这个问题。
可能是什么问题以及如何解决?
这是我的詹金斯管道脚本:
pipeline {
options {
timestamps()
}
agent {
node {
label 'master'
}
}
parameters {
string(name: 'run_script_method', defaultValue: 'test', description: 'the run script method of npm')
string(name: 'env_vars', defaultValue: '', description: 'the ENV variables to set before starting the tests')
}
stages {
stage ('SETUP') {
steps {
script {
cfg = load "./rest/jenkins/config.jenkins"
mp = load "./rest/jenkins/jenkinslib.groovy"
}
}
}
stage ('TESTS') {
steps {
script {
mp.configureLcmApplicationOrRunTests(cfg.environment.BETA, "${run_script_method}", "${env_vars}")
}
}
}
}
}
这是我用来实现具体功能configureLcmApplicationOrRunTests
的二手图书馆:
def configureLcmApplicationOrRunTests(
Map args,
NpmRunScriptMethod,
AdditionalParameters
) {
withDockerContainer(image: 'grme/nightwatch-chrome-firefox:1.0.0', args: "-e JAVA_OPTS=\"-Dselenium.LOGGER.level=WARNING\" -e NpmRunScriptMethod=\"$NpmRunScriptMethod\" -e AdditionalParameters=\"$AdditionalParameters\"") {
sh """
#set +x
echo "======================================================================="
pwd
echo "$NpmRunScriptMethod"
echo "$AdditionalParameters"
echo "======================================================================="
"""
}