jenkins pipeline 模板 git maven npm

node{
    // checkout git
    stage('git checkout'){
        checkout([$class: 'GitSCM'
        , branches: [[name: '*/master']]
        , doGenerateSubmoduleConfigurations: false
        , extensions: []
        , submoduleCfg: []
        , userRemoteConfigs: [[credentialsId: 'GIT_PASSWORD'
        , url: 'GIT_URL']]])    
    }
    
	
    //maven build
    stage('maven build'){
        sh '''
            export JAVA_HOME=/usr/java/jdk1.8.0_162
            /usr/local/maven-3.6.1/bin/mvn clean package -Dmaven.test.skip=true
        '''
    }

    //npm build
    stage('npm build'){
        sh '''
            nodejs=/usr/local/node-${node_version}/bin
            export NODEJS=$nodejs
            PATH=$PATH:$NODEJS
            cnpm install && cnpm run build
        '''
    }
    
	//docker build 
    stage('docker build and push'){
        sh '''
            VERSION=${project_version}
			cat > /docker/build/***-app << EOF
			
FROM openjdk:8-jre-alpine
MAINTAINER www.duanyu.io
ADD ./target/management-system-1.0.0.jar /app/***.jar
ADD application.properties              /app/
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
WORKDIR /app
EXPOSE 8880
ENTRYPOINT ["java","-jar","***.jar","--Dspring.config.location=application.properties"]
EOF

            docker build -t ***-app:$VERSION -f /docker/build/***-app .
        '''
    }
	
	//docker tag and push harbor
	stage(){
		sh '''
			VERSION=${project_version}
			docker tag ***-app:$VERSION harbor.***.***.cn/***/***-app:$VERSION
            docker login harbor.***.***.cn --username=*** --password=***
            docker push harbor.***.***.cn/***/***-app:$VERSION
		'''
	}
}

 

你可能感兴趣的:(持续集成)