im having troubles contructiong my Jenkins Pipeline for what should be an easy scenario.
Im using DockerDesktop running a Jenkins image (https://hub.docker.com/r/jenkinsci/blueocean/). I have a standard react-app that i want to build and run tests after my commits.
The Webhooks configurations already works, but the commands i run inside my Jenkinsfile doesn't seem to work as i expected:
This is my current Jenkinsfile:
node {
def app
stage('Clone repository') {
checkout scm
}
stage('Build image') {
app = docker.build("getintodevops/hellonode", "-f Dockerfile.dev ./")
}
stage('Test image') {
app.inside {
sh 'pwd'
sh 'npm run build'
}
}
}
the Dockerfile-dev looks like this:
FROM node:alpine
COPY ./package.json ./
RUN ["npm", "install"]
COPY ./src/ ./src/
COPY ./public/ ./public/
what i expected was that the commands inside the stage(Test image) would run inside a container with the image i've just build, but the pwd command shows that the commands are exec'd inside the jenkins workspace,containging basically what i have committed on github (/src, /public, package.json ecc..), so when npm run build is launched i get an error for missing the node_modules.
Am I missing something? Shouldn't the commands run on the built image, which i verified has all the necessary folders?
Let me know if other files or configurations im using are necessary
P.S. I've also tried using this kind of Jenkinsfile, but i always have the same issue(even if the agent is defined outside the stage):
pipeline {
agent none
stages {
stage('Build') {
agent{
dockerfile {
filename 'Dockerfile.dev'
}
}
steps {
sh "npm run build"
}
}