I am trying to clone a repo in a server using credentials stored in Jenkins and I am performing certain operations on that repo.
pipeline {
options {
skipDefaultCheckout()
timestamps()
}
parameters {
string(name: 'FILENAME', defaultValue: 'tmp', description: 'Enter the file name that needs to be copied')
string(name: 'DB_NAME', defaultValue: 'tmp_db', description: 'Enter the database name that needs to be created')
string(name: 'VERSION', defaultValue: '1', description: 'Enter the DB name version')
choice(name: 'RUN', choices: 'Migrate Data', description: 'Data migration')
}
agent {
node { label 'myserver' }
}
triggers {
pollSCM('H/5 * * * *')
}
stages {
stage('Clean & Clone') {
steps {
cleanWs()
git(branch: 'jenkinsfilr-branch',
credentialsId: 'lsdeploy-github',
url: 'https://github.com/xyz')
}
}
stage('Run the shell script On-prem'){
steps {
git(branch: 'progress',
credentialsId: 'lsdeploy-github',
url: 'https://github.com/abc')
}
configFileProvider([configFile(fileId: 'env-on-prem', targetLocation: '.env')]) {
sh '''
bash -x ./ops/database-migration/migrate.sh ${FILENAME} ${DB_NAME} ${VERSION}
'''
}
}
}
}
}
The migrate.sh contains operations performed on the abc folder (cloned from https://github.com/abc) while the migrate.sh resides in xyz repo (cloned from https://github.com/xyz). In this case, since abc repo is cloned latest, jenkins throws an error that it can't find the migrate.sh script. Is there any way to avoid this error? I tried to perform git clone --branch progress https://github.com/abc in the migrate.sh script, but it asks me for credentials. I tried the other way, so that I can store the credentials in Jenkins and also clone the repo. Any help?
cdto thexyzdirectory before you run the migrate.sh script. Or alternatively you couldcpthe migrate.sh script to your working directory, and then run it.