我正在尝试将Testing stage添加到我的Jenkins文件中。
我在Jenkins中安装了Docker。
我使用以下命令运行测试:
docker-compose run web python manage.py test
这是我的Jenkins文件:
node{
stage('Checkout'){
def dockerHome = tool 'docker'
env.PATH = "${dockerHome}/bin"
checkout scm
}
stage('Build image') {
withEnv(['PATH+EXTRA=/usr/sbin:/usr/bin:/sbin:/bin']){
sh "docker login --username=mygituks --password=mdj1646MDJ"
sh "docker build -t my_git_uks -f Dockerfile ."
sh "docker tag my_git_uks gituks/uks-git-2019:second"
}
}
stage('Run Tests') {
withEnv(['PATH+EXTRA=/usr/sbin:/usr/bin:/sbin:/bin']){
def testsError = null
try {
sh "docker-compose run web python manage.py test"
}
catch(err) {
testsError = err
echo "Failure"
}
}
}
stage('Push image') {
withEnv(['PATH+EXTRA=/usr/sbin:/usr/bin:/sbin:/bin']){
sh "docker push gituks/uks-git-2019:second"
}
}
}
我得到这个错误: docker-compose:找不到命令
这也是我也尝试过的事情之一,但出现此错误: test.sh:第3行:python:找不到命令
我添加了test.sh:
#!/bin/bash
python manage.py test
并将我的测试阶段更改为:
stage('Run Tests') {
withEnv(['PATH+EXTRA=/usr/sbin:/usr/bin:/sbin:/bin']){
def testsError = null
try {
sh "bash test.sh"
}
catch(err) {
testsError = err
echo "Failure"
}
}
希望有人可以帮助我解决这个问题或给我任何提示。
已解决
node{
stage('Checkout'){
def dockerHome = tool 'docker'
env.PATH = "${dockerHome}/bin"
PATH = "$PATH:/usr/bin"
checkout scm
}
stage('Build image') {
withEnv(['PATH+EXTRA=/usr/sbin:/usr/bin:/sbin:/bin']){
sh "docker login --username=mygituks --password=mdj1646MDJ"
sh "docker build -t my_git_uks -f Dockerfile ."
sh "docker tag my_git_uks gituks/uks-git-2019:second"
}
}
stage('Run Tests') {
withEnv(['PATH+EXTRA=/usr/sbin:/usr/bin:/sbin:/bin']){
echo "PATH is: $PATH"
sh "docker exec my_git_web python manage.py test"
}
}
stage('Push image') {
withEnv(['PATH+EXTRA=/usr/sbin:/usr/bin:/sbin:/bin']){
sh "docker push gituks/uks-git-2019:second"
}
}
}
答案 0 :(得分:0)
您的代理上可能没有安装docker-compose。
您可以:
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
docker.image("docker").inside() {
sh "docker-compose run web python manage.py test"
}