2

I would like to ask on how can I add another step for pulling another repo on the jenkins pipeline I created. You see from the jenkins pipeline settings I already specified a repo for pulling the ui to build. Then after the build is made I need to pull another repo for api and build it as one docker image. I already tried this doc however I'm getting issue on getting the the ui files to combine on the api, here is my pipeline script used.

pipeline {
agent { label 'slave-jenkins'}
stages {blah blah
 }
stage('Workspace Cleanup') {
     steps {
         step([$class: 'WsCleanup'])
         checkout scm
     }
    }
stage('Download and Build UI Files') {
steps {
  sh '''#!/bin/bash
     echo "###########################"
     echo "PERFORMING NPM INSTALL"
     echo "###########################"
     npm install
     echo "###########################"
     echo "PERFORMING NPM RUN BUILD"
     echo "###########################"
     npm run build
     echo "###########################"
     echo "Downloading API Repo"
     echo "###########################"
     **git branch: 'master',**
         **credentialsId: 'XXXXXXXXXXXX',**
         **url: 'ssh://git@XXXXXXe:7999/~lXXXXXX.git'**
     echo ""
     '''
       }
      }
       }
mohan08p
  • 5,002
  • 1
  • 28
  • 36
Ersan Poguita
  • 119
  • 1
  • 2
  • 8

1 Answers1

0

You shouldn't include Jenkins Pipeline DSL into shell script - it must be a separate step, for example

steps {
    // first step to run shell script
    sh '''#!/bin/bash
         echo "###########################"
         echo "PERFORMING NPM INSTALL"
         echo "###########################"
         npm install
         echo "###########################"
         echo "PERFORMING NPM RUN BUILD"
         echo "###########################"
         npm run build
         echo "###########################"
         echo "Downloading API Repo"
         echo "###########################"
    '''
    // second step to checkout git repo
    git branch: 'master',
        credentialsId: 'XXXXXXXXXXXX',
        url: 'ssh://git@XXXXXXe:7999/~lXXXXXX.git'
}

But mixing two repos in one workspace (and two responsibilities in one job) probably isn't a good idea. It would be better if you split your continuous delivery process into multiple jobs:

  • job to build UI;
  • job to build API;
  • job to create Docker image.

and then chain this jobs, so that they are executed one by one and pass build artifacts to each other. So each part of your CD process will satisfy the principle of single responsibility.

Alexey Prudnikov
  • 1,083
  • 12
  • 11