我需要每天晚上轮询工件URL,找出添加了哪个文件,然后使用新工件的名称作为参数来触发Jenkins中的另一个作业。但是URLTrigger插件不会返回新工件的名称吗?有什么方法可以推导那个?
答案 0 :(得分:0)
我使用groovy运行curl命令以提取并解析metas.xml以得出jar名称。
假设Artifactory的元数据内容如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>path.to.application</groupId>
<artifactId>jarName</artifactId>
<versioning>
<latest>6.1.12-SNAPSHOT</latest>
<release>6.1.11</release>
<versions>
<version>6.1.11</version>
<version>6.1.12-SNAPSHOT</version>
</versions>
<lastUpdated>20181122121509</lastUpdated>
</versioning>
</metadata>
因此我想要的构建信息是'jarName-6.1.12-SNAPSHOT.jar'
import org.xml.sax.SAXParseException;
//Assumed artifactory path to application.jar
def metaDataPath = 'https://your.artifactory.server/artifactory/path/to/application/jarName/maven-metadata.xml'
//Get the file using curl (you might need to use a proxy), with an api token for authentication
def metadataContent = 'curl -x<your-proxy:80> -H "X-JFrog-Art-Api:<your token>" -XGET ' + metaDataPath
metadataContent = metadataContent.execute().text
//Parse it to get the 'latest' element
def parsedXml = (new XmlParser()).parseText(metadataContent)
println parsedXml.versioning.latest.text() //6.1.12-SNAPSHOT
如果快照构建的名称中包含时间戳,则需要使用返回的6.1.12-SNAPSHOT
来构建新的元数据路径:
https://your.artifactory.server/artifactory/path/to/application/jarName/6.1.12-SNAPSHOT/maven-metadata.xml
然后重复提取和解析过程以从子metadata.xml获取带有时间戳的名称