Reputation: 1542
Creating a Pipeline to read a Dockerfile and create container for this app be run.
Jenkinsfile:
pipeline {
agent any
tools {nodejs "node" }
stages {
stage('Cloning Git') {
steps {
git url: 'https://github.com/user/private-repo.git',
credentialsId: 'Git-2'
}
}
stage('Build Container Image') {
steps {
agent{
dockerfile {
filename '$workspace/Dockerfile',
label 'node'
}
}
}
}
stage('Build') {
steps {
sh 'npm install'
}
}
stage('Test') {
steps {
sh "pwd"
}
}
}
}
Error:
WorkflowScript: 15: Expected a step @ line 15, column 15. filename '$workspace/Dockerfile',
I was reading this article Using Docker with Pipeline. I new in Jenkins and in my mind, I was thinking in this steps:
But as I don't know how to deal with Jenkins I'm kind lost here.
Dockerfile:
FROM node
RUN apt-get update && apt-get upgrade -y \
&& apt-get clean
RUN mkdir /app
WORKDIR /app
COPY package*.json /app/
RUN npm install
COPY src /app/src
EXPOSE 3000
CMD [ "npm", "start" ]
Anyone can please help me, or suggest an article?
Upvotes: 0
Views: 1413
Reputation: 1050
Using docker and Jenkins can be fairly complicated. The first question you usually need to ask is how complicated of a Jenkins build do you need to do? If you are just trying to run a container that houses your build, you can usually just use a declarative pipeline.
However, I find that anything more than that, usually requires a scripting pipeline. With a scripting pipeline, the logic is usually a little more complicated, but it is closer to native groovy.
https://www.jenkins.io/doc/book/pipeline/docker/#building-containers
A good overview of how to make this work is located https://tutorials.releaseworksacademy.com/learn/building-your-first-docker-image-with-jenkins-2-guide-for-developers
As a note, you should not be calling npm install from your jenkinsfile. This should only be executed from within the docker container during the build process.
Checkout source code. You can either configure the jenkins server to know what your upstream repository is, or you can follow the steps here to add a URL and credentials.
Build your dockerfile
Push/tag your docker image to a registry as shown in the above tutorial and here
Upvotes: 3