Skip to content

Instantly share code, notes, and snippets.

@DevJulianSalas
Last active May 28, 2021 19:10
Show Gist options
  • Save DevJulianSalas/74056fe96e9a880acf0cc20d68d2abd2 to your computer and use it in GitHub Desktop.
Save DevJulianSalas/74056fe96e9a880acf0cc20d68d2abd2 to your computer and use it in GitHub Desktop.
A Jenkinsfile pipeline to run ci/cd in Node-react environment from gitlab push events. This is to gitlab repo generating a toke from user with permissons
pipeline {
agent { dockerfile true }
environment{
user=credentials('here-your-credential-from-jenkins-credentials') // To get credentials go credentials jenkins link and copy id credential.
}
options {
gitLabConnection('xxx') // Here go your connection with gitlab, you can set up it jenkins credentials, dont forget install plugin gitlab to jenkins
gitlabBuilds(builds: ['install', 'test', 'build','pre-deploy'])
}
triggers {
gitlab(triggerOnPush: true, branchFilterType: 'All') //add here your events to tigger from gitlab and what branchs you want to filter.
}
stages {
stage("install") {
steps {
sh 'yarn install'
}
}
stage("styles"){
steps{
sh 'yarn styles'
}
}
stage("test"){
steps {
sh 'yarn test'
}
}
stage("build"){
steps{
sh('yarn build')
}
}
stage("pre-deploy"){
steps{
sh('ls -la')
sh('pwd')
sh('sshpass -p $xxx ssh -o StrictHostKeyChecking=no $xxx@$xx -tt date') here a test to connect by ssh
sh('sshpass -p $xxx scp -v -r $WORKSPACE/build $user@$host:"/dir"')
sh('sshpass -p $xxx ssh -o StrictHostKeyChecking=no $user@$host -t "echo $user | sudo -S cp -r path path/public_html"')
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment