Demo-Test-NodeJS-Nginx

不管现实多么惨不忍睹,都要持之以恒地相信,这只是黎明前短暂的黑暗而已。不要惶恐眼前的难关迈不过去,不要担心此刻的付出没有回报,别再花时间等待天降好运。真诚做人,努力做事!你想要的,岁月都会给你。Demo-Test-NodeJS-Nginx,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

/*
//==========通用变量信息=========
def GitAddr = "https://git.nercoa.com/fz/other/uc/sprout.git"
def Branch = "master"
def ImageTag = "v1.0.0"
def Project = "vue-nodejs"
def App_name = "backstage"
def PortNumber "38081"

//====================以上变量可在新建Job任务时使用字符参数进行插入=====================

*/
 //Job Start!!
 
    //阶段1:拉取代码,node 节点未指定,则在Master执行,因为Git、Maven 环境都在 Master,所以就在主节点执行了
stage(' Git Checkout') {
    node('MSBuild') {
       checkout([$class: 'GitSCM', branches: [[name: '${Branch}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '973c9a08-4d62-4f8a-8792-7a214b7ffe66', url: '${GitAddr}']]])
    }
}

    //阶段2:Dotnet编译代码
stage('Build'){
    node('MSBuild') {
       echo '编译解决方案'
       bat "cd src/${App_name} && npm install && npm run build"
    }
}

stage('Backup To The Site Directory'){
    node('MSBuild') {
//        dir('dist') {
        bat "cd src/${App_name}  && zip -r ${BUILD_NUMBER}.zip dist/*"
//        }
        echo '拷贝文件至备份目录'
        bat "echo d | xcopy /e /y /r /f src\\${App_name}\\${BUILD_NUMBER}.zip \"${BACKUP_SHARE_DIR}/${JOB_NAME}/\""
        bat "rm -rf src\\${App_name}\\dist && rm -rf src\\${App_name}\\*.zip"        
   }
}

stage('Download Project Code'){
    node('TestEnv') {
        //echo '建立业务目录' #会在 workspace 下自动创建任务目录
        //sh "mkdir -p ${JOB_NAME} && cd ${JOB_NAME}"
        echo '下载程序'
        sh "curl -O http://rls.nercoa.com/${JOB_NAME}/${BUILD_NUMBER}.zip"
        echo '解压源程序'
        sh "unzip -o *.zip && mv -f dist/* ./ && rm -rf *.zip dist"
    }
}    

    
    //阶段3:构建Docker镜像并推送到私有仓库
stage('Build And Push Image') {
    node('TestEnv') { 
        sh '''
        REPOSITORY=harbor.nercoa.com/${Project}/${App_name}:${ImageTag}
        cat > Dockerfile << EOF
        #注意选择镜像镜像版 
        FROM nginx
        MAINTAINER WinJayX <WinJayX@Gmail.com>
        LABEL description="This is NodeJS Project"
        LABEL version="0.1"
        USER root

        COPY . /usr/share/nginx/html

EOF

        docker build -t $REPOSITORY .
        docker login harbor.nercoa.com -u admin -p Nerc.nerc/1
        docker push $REPOSITORY
        rm -rf *
        '''
    }
}

    //阶段4:部署到远程Node Docker主机节点
stage('Deploy To The Test Server') {
    node('TestEnv') { 
        sh '''
        REPOSITORY=harbor.nercoa.com/${Project}/${App_name}:${ImageTag}
        docker rm -f ${App_name} || true
        docker container run -d \
        --volume /etc/localtime:/etc/localtime:ro \
        --restart always \
        --user root \
        --name ${App_name} \
        --hostname ${App_name} \
        -p ${PortNumber}:80 $REPOSITORY
        '''
    }
}


/* 
    //阶段5:  获取站点的状态  
stage('Test the WebSite') {
    node('Node12') {
        sh '''
        curl -I -m 10 -o /dev/null -s -w %{http_code} 202.205.161.114:39096
        '''
    }
}

   
stage('Deploying To The Production Server'){
    timeout(time: 1, unit: 'DAYS') {
    input message: 'Deploying To The Production Server?', ok: 'Deployment'
    }
}

 
    //阶段6:部署到生产环境服务器,||true 短路逻辑运算,只有前面返回假echo $? =1 时,后面才执行

stage('Deploy To The Production Docker Server') {
//      方式1 执行远程服务器上的脚本文件
//    node {
//        sh '''
//        ssh root@202.205.161.131 "cd /home/docker/003.CourseDetectionWeb ; sh docker_CourseDetectionSystem.start.sh"
//        '''
//    }

      //方式2
    node('Node12') { 
        sh '''
        cd /home/Docker/009.FZ.VR.Authorizationsystem
        REPOSITORY=harbor.nercoa.com/fz_vr/authorization:${ImageTag}
        docker rm -f VR_Auth || true
        docker container run -d \
        --volume /etc/localtime:/etc/localtime:ro \
        --volume `pwd`/Config:/app/Config \
        --restart always \
        --user root \
        --name VR_Auth \
        --hostname VR_Auth \
        -p 8009:80 \
        $REPOSITORY
        '''
  }
}
*/

image.png

image.png

image.png

image.png

V2

/*
//==========通用变量信息=========
def GitAddr = "https://git.nercoa.com/fz/other/uc/sprout.git"
def Branch = "master"
def ImageTag = "v1.0.0"
def Project = "vue-nodejs"
def App_name = "backstage"
def PortNumber "38081"

//====================以上变量可在新建Job任务时使用字符参数进行插入=====================

*/
 //Job Start!!
 
    //阶段1:拉取代码,node 节点未指定,则在Master执行,因为Git、Maven 环境都在 Master,所以就在主节点执行了
stage(' Git Checkout') {
    node('MSBuild') {
       checkout([$class: 'GitSCM', branches: [[name: '${Branch}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '973c9a08-4d62-4f8a-8792-7a214b7ffe66', url: '${GitAddr}']]])
    }
}

    //阶段2:Dotnet编译代码
stage('Build'){
    node('MSBuild') {
       echo '编译解决方案'
       bat "cd src/${App_name} && npm install && npm run build"
    }
}

stage('Backup To The Site Directory'){
    node('MSBuild') {
//        dir('dist') {
        bat "cd src/${App_name}  && zip -r ${BUILD_NUMBER}.zip dist/*"
//        }
        echo '拷贝文件至备份目录'
        bat "echo d | xcopy /e /y /r /f src\\${App_name}\\${BUILD_NUMBER}.zip \"${BACKUP_SHARE_DIR}/${JOB_NAME}/\""
        bat "rm -rf src\\${App_name}\\dist && rm -rf src\\${App_name}\\*.zip"        
   }
}

stage('Download Project Code'){
    node('TestEnv') {
        //echo '建立业务目录' #会在 workspace 下自动创建任务目录
        //sh "mkdir -p ${JOB_NAME} && cd ${JOB_NAME}"
        echo '下载程序'
        sh "curl -O http://rls.nercoa.com/${JOB_NAME}/${BUILD_NUMBER}.zip"
        echo '解压源程序'
        sh "unzip -o *.zip && mv -f dist/* ./ && rm -rf *.zip dist"
    }
}    

    
    //阶段3:构建Docker镜像并推送到私有仓库
stage('Build And Push Image') {
    node('Container') { 
        sh '''
        REPOSITORY=harbor.nercoa.com/${Project}/${App_name}:${ImageTag}
        cat > Dockerfile << EOF
        #注意选择镜像镜像版 
        FROM nginx
        MAINTAINER WinJayX <WinJayX@Gmail.com>
        LABEL description="This is NodeJS Project"
        LABEL version="0.1"
        USER root

        COPY . /usr/share/nginx/html

EOF

        docker build -t $REPOSITORY .
        docker login harbor.nercoa.com -u admin -p Nerc.nerc/1
        docker push $REPOSITORY
        rm -rf *
        '''
    }
}

    //阶段4:部署到远程Node Docker主机节点
stage('Deploy To The Test Server') {
    node('TestEnv') { 
        sh '''
        REPOSITORY=harbor.nercoa.com/${Project}/${App_name}:${ImageTag}
        docker rm -f ${App_name} || true
        docker container run -d \
        --volume /etc/localtime:/etc/localtime:ro \
        --restart always \
        --user root \
        --name ${App_name} \
        --hostname ${App_name} \
        -p ${PortNumber}:80 $REPOSITORY
        '''
    }
}


/* 
    //阶段5:  获取站点的状态  
stage('Test the WebSite') {
    node('Node12') {
        sh '''
        curl -I -m 10 -o /dev/null -s -w %{http_code} 202.205.161.114:39096
        '''
    }
}

   
stage('Deploying To The Production Server'){
    timeout(time: 1, unit: 'DAYS') {
    input message: 'Deploying To The Production Server?', ok: 'Deployment'
    }
}

 
    //阶段6:部署到生产环境服务器,||true 短路逻辑运算,只有前面返回假echo $? =1 时,后面才执行

stage('Deploy To The Production Docker Server') {
//      方式1 执行远程服务器上的脚本文件
//    node {
//        sh '''
//        ssh root@202.205.161.131 "cd /home/docker/003.CourseDetectionWeb ; sh docker_CourseDetectionSystem.start.sh"
//        '''
//    }

      //方式2
    node('Node12') { 
        sh '''
        cd /home/Docker/009.FZ.VR.Authorizationsystem
        REPOSITORY=harbor.nercoa.com/fz_vr/authorization:${ImageTag}
        docker rm -f VR_Auth || true
        docker container run -d \
        --volume /etc/localtime:/etc/localtime:ro \
        --volume `pwd`/Config:/app/Config \
        --restart always \
        --user root \
        --name VR_Auth \
        --hostname VR_Auth \
        -p 8009:80 \
        $REPOSITORY
        '''
  }
}
*/

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/160299.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!