Jenkins-码头工人:找不到

时间:2020-06-10 02:56:30

标签: node.js docker jenkins raspberry-pi

我刚开始使用docker和jenkins很新,但是想看看我是否可以让一个节点应用程序自动部署并在我的树莓派上运行。在理想的世界中,我想让Jenkins从github下拉代码,使用jenkinsfile和dockerfile来构建和运行docker映像(希望这是可能的)。

jenkinsfile

pipeline {
    agent {
        dockerfile true
    }
    environment {
        CI = 'true' 
        HOME = '.'
    }
    stages {
        stage('Install dependencies') {
            steps {
                sh 'npm install'
            }
        }
        stage('Test') { 
            steps {
                sh './scripts/test' 
            }
        }
        stage('Build Container') { 
            steps {
                sh 'docker build -t test-app:${BUILD_NUMBER} . ' 
            }
        }
    }
}

dockerfile

 # Create image based on the official Node image
FROM node:12

# Create a directory where our app will be placed
RUN mkdir -p /usr/src/app

# Change directory so that our commands run inside this new directory
WORKDIR /usr/src/app

# Copy dependency definitions
COPY package.json /usr/src/app

# Install dependecies
RUN npm install

# Get all the code needed to run the app
COPY . /usr/src/app

# Expose the port the app runs in
EXPOSE 3000

# Serve the app
CMD ["npm", "start"]

但是,当我尝试在jenkins中运行此命令时,出现以下错误: ../ script.sh:docker:未找到。任何docker命令似乎都是这种情况。我实际上尝试运行其他以'sudo'开头的命令,但它抱怨 sudo:not 。是否缺少步骤,还是我尝试以错误的方式进行操作? (注意:docker已安装在raspberry pi上。我可以使用jenkins用户登录并执行docker命令。它只是无法通过网络ui使用)。任何建议将不胜感激。

谢谢!

1 个答案:

答案 0 :(得分:0)

显然,此部分是在破坏它:

agent {
    dockerfile true
}

设置此项时:

agent any

它完成了构建,包括没有任何问题的docker命令。我想我只是不明白那部分是如何工作的。任何解释都会有所帮助!