Newer
Older
MazeGame / Jenkinsfile
@Pascal Syma Pascal Syma on 23 Jan 2020 2 KB fixed ssh put
pipeline {
    agent {
        label 'node&&windows'
    }
   environment {
     scmUrl = scm.getUserRemoteConfigs()[0].getUrl()
   }

    stages {
        stage ('Initialize') {
            steps {
                echo 'Initializing..'
            }
        }
        stage('Build') {
            steps {
                echo 'Building..'
                bat 'npm install'
                bat 'npm run prod'
            }
        }
        stage('Test') {
            steps {
                echo 'Testing..'
            }
        }
        stage('Archive') {
            when {
              branch 'master'
              expression {
                currentBuild.result == null || currentBuild.result == 'SUCCESS'
              }
            }
            steps {
                echo 'Deploying....'
                dir("public") {
                    bat 'git init'
                    bat 'git add .'
                    bat 'git config --global user.email "jenkins@bosym.de"'
                    bat 'git config --global user.name "Jenkins"'
                    bat 'git commit -m "Deploy by Jenkins"'
                    withCredentials([usernamePassword(credentialsId: 'e3d97a6f-476f-489f-a207-4766a1c420cf', usernameVariable: 'username', passwordVariable: 'password')])
                    {
                        bat "git push --force --quiet \"https://$username:$password@git.bosym.de/MaMa/MazeGame.git\" master:gh-pages"
                    }
                    withCredentials([sshUserPrivateKey(credentialsId: 'id_rsa', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'userName')])
                    {
                        script {
                            def remote = [:]
                            remote.name = "1blu"
                            remote.host = "webhosting72.1blu.de"
                            remote.allowAnyHosts = true
                            remote.user = userName
                            remote.identityFile = identity

                            sshCommand remote: remote, command: "mkdir ./releases/${BUILD_NUMBER}"
                            sshPut remote: remote, from: "${WORKSPACE}\\public\\", into: "./releases/${BUILD_NUMBER}"
                            sshCommand remote: remote, command: "rm www/mama.productions/public"
                            sshCommand remote: remote, command: "ln -s ../../releases/${BUILD_NUMBER}/public www/mama.productions/public"
                        }
                    }
                }
                deleteDir()
            }
        }
    }
}