我有一个Angular webapp,我想使用Jenkins声明式管道作为工件发布到Artifactory。我该怎么做?
答案 0 :(得分:0)
要上传到Artifactory,请使用rtUpload命令。例如:
steps {
sh 'npm run build:production'
echo "Deploy to Artifactory"
script {
VERSION = sh(script: 'cat package.json | grep \'version\' | grep -o -E \'[0-9]+\\.[0-9]+\\.[0-9]+(\\-SNAPSHOT)?\'',
returnStdout: true).trim()
}
sh "sed 's/REPLACE_VERSION_HERE/${VERSION}/g' upload-pom.xml.template > upload-pom-${VERSION}.xml"
zip zipFile: "myapp-webapp-${VERSION}-distribution.zip", archive: true, dir: 'dist'
rtUpload (
serverId: "main",
spec:
"""{
"files": [
{
"pattern": "myapp-webapp-(*)-distribution.zip",
"target": "reponame/com/company/product/myapp-webapp/{1}/myapp-webapp-{1}-distribution.zip"
},
{
"pattern": "upload-pom-(*).xml",
"target" : "reponame/com/company/product/myapp-webapp/{1}/myapp-webapp-{1}.pom"
}
]
}""",
failNoOp: true
)
}
代码执行以下操作:
npm
生产版本package.json
提取到VERSION
变量中。pom.xml
文件dist
目录的zip。rtUpload
命令上传zip文件+ pom文件上载pom文件以确保以此方式上载的SNAPSHOT版本可以正常工作。没有它,Artifactory不会生成Maven元数据,并且Maven将不会下载新的SNAPSHOT版本(例如,如果您在基于Maven的Spring Boot应用程序中使用此工件)。这样,Maven一切都可以正常工作。
upload-pom.xml.template
应该看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.product</groupId>
<artifactId>myapp-webapp</artifactId>
<version>REPLACE_VERSION_HERE</version>
<packaging>zip</packaging>
<description>Dummy pom.xml for Artifactory</description>
</project>