-1

I just followed this tutorial to get a basic React setup going with Jenkins. In the tutorial they work directly in the React client folder and I'm now trying to get a setup where the client folder is nested within a parent directory which is my root directory with the content looking like:

Organizer (dir):

  • client (dir)
  • jenkins (dir containing scripts)
  • Jenkinsfile
  • node_modules (dir)
  • package.json
  • package-lock.json

The problem I'm having now is that when the Jenkinsfile:

pipeline {
    agent {
        docker {
            image 'node:6-alpine'
            args '-p 3000:3000'
        }
    }
    environment {
        CI = 'true'
    }
    stages {
        stage('Build') {
            steps {
                sh 'npm install'
            }
        }
        stage('Test') {
            steps {
                sh './jenkins/scripts/test.sh'
            }
        }
    }
}

invokes test.sh:

#!/usr/bin/env sh

echo 'The following "npm" command (if executed) installs the "cross-env"'
echo 'dependency into the local "node_modules" directory, which will ultimately'
echo 'be stored in the Jenkins home directory. As described in'
echo 'https://docs.npmjs.com/cli/install, the "--save-dev" flag causes the'
echo '"cross-env" dependency to be installed as "devDependencies". For the'
echo 'purposes of this tutorial, this flag is not important. However, when'
echo 'installing this dependency, it would typically be done so using this'
echo 'flag. For a comprehensive explanation about "devDependencies", see'
echo 'https://stackoverflow.com/questions/18875674/whats-the-difference-between-dependencies-devdependencies-and-peerdependencies.'
set -x
# npm install --save-dev cross-env
set +x

echo 'The following "npm" command tests that your simple Node.js/React'
echo 'application renders satisfactorily. This command actually invokes the test'
echo 'runner Jest (https://facebook.github.io/jest/).'
set -x
pwd
npm test

npm test isn't recognised because where the script is being ran from /var/jenkins_home/workspace/organizer is not the client folder where the package.json file defines what npm test does. I need to somehow run 'npm test' from inside the client folder which is a subdirectory of organizer. How do I go about doing this? It has also occured to me that the npm install is in completely the wrong place also. The error logs provide the following.

+ pwd

/var/jenkins_home/workspace/organizer

+ npm test


> organizer@1.0.0 test /var/jenkins_home/workspace/organizer

> echo "Error: no test specified" && exit 1


Error: no test specified

npm ERR! Test failed.  See above for more details.

script returned exit code 1```



byte_baron
  • 73
  • 1
  • 1
  • 5

1 Answers1

0

I changed the test stage in my Jenkinsfile to resemble the below to fix my problem:

stage('Test') {
            steps {
                sh '''
                        cd client
                        ../jenkins/scripts/test.sh
                '''
            }
        }
byte_baron
  • 73
  • 1
  • 1
  • 5