在Jenkins中使用Jekyll泊坞窗

时间:2018-12-06 14:02:25

标签: docker jenkins jenkins-pipeline jekyll

我正在尝试通过我的Jenkins服务器(在容器内运行)构建一个jekyll网站,并且我的Jenkinsfile中有一个如下所示的阶段:

stage('Building Website') {

      agent {

        docker {
            image 'jekyll/jekyll:builder'
        }

      }

      steps {
        sh 'jekyll --version'
      }
}

我第一次运行我的工作时,它会拉开jekyll docker映像并运行良好(尽管在运行jekyll之前它确实获取了很多宝石,但是当我在jenkins外部手动运行docker时不会发生)作业失败并显示此错误:

jekyll --version
/usr/jekyll/bin/jekyll: exec: line 15: /usr/local/bundle/bin/jekyll: not found

有什么想法我在这里做错了吗?

1 个答案:

答案 0 :(得分:3)

As you can see in the jenkins log file, jenkins runs docker with the -u 1000:1000 argument, since this user does not exits in the jekyll/jekyll image, the command fails with the error .../bin/jekyll: not found

Here is a sample Jenkinsfile:

pipeline {
    agent
    {
        docker
        {
            image 'jekyll/jekyll:3.8'
            args '''
                -u root:root
                -v "${WORKSPACE}:/srv/jekyll"
            '''
        }
    }
    stages {
        stage('Test') {
            steps {
                sh '''
                    cd /srv/jekyll
                    jekyll --version
                '''
            }
        }
    }
}