jenkinsfile脚本如何准确找出构建jar包阶段生成的所有target/maven-archiver/pom.properties文件?并且如何将groupId、artifactId、version取出来,不用new的方法,用最简单的方法写出来

时间: 2024-04-15 08:28:16 浏览: 16
要准确找出构建阶段生成的所有pom.properties文件,可以使用`findFiles`方法来搜索指定目录下的文件。然后,使用Groovy的`each`方法遍历找到的文件列表,并提取其中的groupId、artifactId和version信息。 以下是一个示例的Jenkinsfile脚本,使用了`findFiles`和`each`方法来查找和提取pom.properties文件中的信息: ```groovy pipeline { agent any stages { stage('Build') { steps { // 构建你的jar包 // 示例:生成pom.properties文件 sh 'echo "groupId=com.example" > target/maven-archiver/pom.properties' sh 'echo "artifactId=my-app" >> target/maven-archiver/pom.properties' sh 'echo "version=1.0.0" >> target/maven-archiver/pom.properties' } } stage('Extract Information') { steps { script { def files = findFiles(glob: 'target/maven-archiver/pom.properties') files.each { file -> def fileContent = file.readToString() def groupId = fileContent =~ /groupId=(.*)/ ? fileContent =~ /groupId=(.*)/ : '' def artifactId = fileContent =~ /artifactId=(.*)/ ? fileContent =~ /artifactId=(.*)/ : '' def version = fileContent =~ /version=(.*)/ ? fileContent =~ /version=(.*)/ : '' echo "groupId: ${groupId[0][1]}" echo "artifactId: ${artifactId[0][1]}" echo "version: ${version[0][1]}" } } } } } } ``` 在这个示例中,我们首先使用`findFiles`方法来搜索`target/maven-archiver/pom.properties`文件。然后,使用`each`方法遍历找到的文件列表,并逐个提取其中的groupId、artifactId和version信息。 请注意,在提取信息时,我们使用了正则表达式和Groovy的匹配运算符`=~`。如果匹配成功,将提取的信息保存在相应的变量中。最后,使用`echo`方法打印出groupId、artifactId和version信息。 这种方法是一种简单且准确的方式来找出构建阶段生成的所有pom.properties文件,并提取其中的信息,而无需使用`new`关键字。

相关推荐

D:\springboot\hspedu_springboot_vue>mvn org.springframework.boot:spring-boot-maven-plugin:run [INFO] Scanning for projects... Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/maven-metadata.xml Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/maven-metadata.xml (7.2 kB at 2.6 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/3.1.0/spring-boot-maven-plugin-3.1.0.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/3.1.0/spring-boot-maven-plugin-3.1.0.pom (3.2 kB at 4.1 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/3.1.0/spring-boot-maven-plugin-3.1.0.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/3.1.0/spring-boot-maven-plugin-3.1.0.jar (130 kB at 108 kB/s) [INFO] [INFO] ------------------< org.apache.maven:standalone-pom >------------------- [INFO] Building Maven Stub Project (No POM) 1 [INFO] --------------------------------[ pom ]--------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 6.851 s [INFO] Finished at: 2023-05-31T00:33:26+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.1.0:run (default-cli): Goal requires a project to execute but there is no POM in this directory (D:\springboot\hspedu_springboot_vue). Please verify you invoked Maven from the correct directory. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException怎么解决

最新推荐

recommend-type

解决java maven项目找不到jconsole-1.8.0.jar和tools-1.8.0.jar包问题

主要介绍了解决java maven项目找不到jconsole-1.8.0.jar和tools-1.8.0.jar包问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
recommend-type

Maven pom.xml与settings.xml详解

主要介绍了Maven pom.xml与settings.xml详解的相关资料,这里对pom.xml与setting.xml详细的研究说明,需要的朋友可以参考下
recommend-type

java 中maven pom.xml文件教程详解

主要介绍了java 中maven pom.xml文件教程详解,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
recommend-type

使用jenkins+maven+git发布jar包过程详解

主要介绍了使用jenkins+maven+git发布jar包过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
recommend-type

解决idea使用maven编译正常但是运行项目时却提示很多jar包找不到的问题

主要介绍了解决idea使用maven编译正常但是运行项目时却提示很多jar包找不到的问题,本文分多种情形给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

list根据id查询pid 然后依次获取到所有的子节点数据

可以使用递归的方式来实现根据id查询pid并获取所有子节点数据。具体实现可以参考以下代码: ``` def get_children_nodes(nodes, parent_id): children = [] for node in nodes: if node['pid'] == parent_id: node['children'] = get_children_nodes(nodes, node['id']) children.append(node) return children # 测试数
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。