jenkins推送mexus
...大约 1 分钟
jenkins推送mexus
1.配置参数化构建
2.拉取代码
git branch: 'master', credentialsId: 'XXXXXXXXXXXXXXXXXXXXXXXXX', url: 'http://xxxx.xxxx.xxxx/xxx/demo.git'
3.打包
sh 'mvn clean package -f pom.xml'
4.推送
script {
pom = readMavenPom file: "pom.xml";
filesByGlob = findFiles(glob: "target/*.${pom.packaging}");
echo "${filesByGlob[0].name} ${filesByGlob[0].path} ${filesByGlob[0].directory} ${filesByGlob[0].length} ${filesByGlob[0].lastModified}"
artifactPath = filesByGlob[0].path;
artifactExists = fileExists artifactPath;
if(artifactExists) {
echo "*** File: ${artifactPath}, group: ${pom.groupId}, packaging: ${pom.packaging}, version ${version}";
nexusArtifactUploader(
nexusVersion: NEXUS_VERSION,
protocol: NEXUS_PROTOCOL,
nexusUrl: NEXUS_URL,
groupId: pom.groupId,
version: version,
repository: NEXUS_REPOSITORY,
credentialsId: NEXUS_CREDENTIAL_ID,
artifacts: [
[artifactId: pom.artifactId,
classifier: '',
file: artifactPath,
type: pom.packaging],
[artifactId: pom.artifactId,
classifier: '',
file: "pom.xml",
type: "pom"]
]
);
} else {
error "*** File: ${artifactPath}, could not be found";
}
}
5.发送邮件通知 (可选)
post {
always {
emailext(
subject: '${DEFAULT_SUBJECT}',
body: '${DEFAULT_CONTENT}',
to: 'XXXXXXXXX@qq.com'
)
}
}
6.完整配置 (可根据环境自行配置)
pipeline {
agent {
docker {
image 'maven:3.8-openjdk-8-slim'
args '-v /root/.m2:/root/.m2'
}
}
environment {
NEXUS_VERSION = "nexus3"
NEXUS_PROTOCOL = "http"
NEXUS_URL = "XXX.XXXX.XXX"
NEXUS_REPOSITORY = "maven-${type}"
NEXUS_CREDENTIAL_ID = "XXXXXXXXXXXXXXXXXXXX"
}
stages {
stage("拉取代码"){
steps {
git branch: 'master', credentialsId: 'XXXXXXXXXXXXXXXXXXXXXXXXX', url: 'http://xxxx.xxxx.xxxx/xxx/demo.git'
}
}
stage('打包项目') {
steps() {
sh 'mvn clean package -f pom.xml'
}
}
stage('上传私服') {
steps {
script {
pom = readMavenPom file: "pom.xml";
filesByGlob = findFiles(glob: "target/*.${pom.packaging}");
echo "${filesByGlob[0].name} ${filesByGlob[0].path} ${filesByGlob[0].directory} ${filesByGlob[0].length} ${filesByGlob[0].lastModified}"
artifactPath = filesByGlob[0].path;
artifactExists = fileExists artifactPath;
if(artifactExists) {
echo "*** File: ${artifactPath}, group: ${pom.groupId}, packaging: ${pom.packaging}, version ${version}";
nexusArtifactUploader(
nexusVersion: NEXUS_VERSION,
protocol: NEXUS_PROTOCOL,
nexusUrl: NEXUS_URL,
groupId: pom.groupId,
version: version,
repository: NEXUS_REPOSITORY,
credentialsId: NEXUS_CREDENTIAL_ID,
artifacts: [
[artifactId: pom.artifactId,
classifier: '',
file: artifactPath,
type: pom.packaging],
[artifactId: pom.artifactId,
classifier: '',
file: "pom.xml",
type: "pom"]
]
);
} else {
error "*** File: ${artifactPath}, could not be found";
}
}
}
}
}
post {
always {
emailext(
subject: '${DEFAULT_SUBJECT}',
body: '${DEFAULT_CONTENT}',
to: 'XXXXXXXXX@qq.com'
)
}
}
}
Powered by Waline v2.15.5