pipeline {
    agent {
        dockerfile {
            filename 'Dockerfile'
            registryUrl 'https://registry.docker-cn.com'
            additionalBuildArgs '--no-cache'
            args '-p 80:80 -p 81:81 -p 82:82 --security-opt apparmor=unconfined'
        }
    }
    stages {
        stage('SonarQube Analysis') {
            steps {
                sh 'sonar-scanner'
            }
        }
        stage('Build Dev Gitbook') {
            steps {
                sh 'gitbook install ./gitbook/dev'
                sh 'gitbook build ./gitbook/dev'
            }
        }
        stage('Build Product Gitbook') {
            steps {
                sh 'gitbook install ./gitbook/product'
                sh 'gitbook build ./gitbook/product'
            }
        }

        stage('Install') {
            steps {
                sh 'cnpm cache clean --force'
                sh 'cnpm cache verify'
                sh 'cnpm install'
                // sh 'cnpm install'   2018/9/5 有报告cnpm会在这里出错  暂时用回npm

            }
        }

        stage('Build'){
            steps {
                sh 'npm run build'
            }
        }
        stage('Deliver'){
            steps {
                sh 'echo $! > .pidfile'
                sh 'service nginx start'
                input message: 'Finished using the web site? (Click "Proceed" to continue)'
            }
        }
            
    }
    post { 
        always { 
            cleanWs()
        }
    }
}