【问题标题】:The requested profile "docker" could not be activated because it does not exist请求的配置文件“docker”无法激活,因为它不存在
【发布时间】:2021-07-11 06:55:26
【问题描述】:

我有一个简单的 Spring 启动应用程序,我想使用 Jenkins 为其构建 docker 映像,但出现错误:

詹金斯错误:

    + /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/M3/bin/mvn clean package -DreleaseVersion=main.39.4c278b3.102 -DdevelopmentVersion=0.0.1-SNAPSHOT -DskipTests -Pdocker docker:push
[INFO] Scanning for projects...
Progress (2): 20 kB | 14 kB   
                           
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml (14 kB at 37 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml (20 kB at 54 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.200 s
[INFO] Finished at: 2021-04-16T06:21:07Z
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "docker" could not be activated because it does not exist.
[ERROR] No plugin found for prefix 'docker' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/var/lib/jenkins/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR] 
  [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

我的 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.pomelo</groupId>
    <artifactId>Pomelo-Assignment</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Pomelo-Assignment</name>
    <description>Pomelo project for Spring Boot assignment</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
      
</project>

我的詹金斯档案:

node {......
    dir('App') {
        stage 'Build docker image'
        def pom = readMavenPom file: 'pom.xml'
        def v = version()
        sh "${mvnHome}/bin/mvn clean package -DreleaseVersion=${v} -DdevelopmentVersion=${pom.version} -DskipTests -Pdocker docker:push"
    }
}
def version() {
  sh('git rev-parse --abbrev-ref HEAD > GIT_BRANCH')
  sh('git describe --long --tags --dirty --always > GIT_COMMIT')
  sh('git rev-list HEAD | wc -l > GIT_LOG_NO')

  def branch = readFile('GIT_BRANCH').trim();
  def hash = readFile('GIT_COMMIT').trim();
  def number = readFile('GIT_LOG_NO').trim();
  "${branch}.${number}.${hash}.${currentBuild.number}"
}

【问题讨论】:

  • 但是你没有在 pom 文件中定义任何配置文件,这就是错误所说的
  • @Setu 如何为 docker 定义?请问你能帮忙吗
  • 我并没有真正得到这个问题;在 maven 中定义配置文件就像 &lt;profiles&gt;&lt;profile&gt;&lt;id&gt;docker&lt;/id&gt;&lt;/profile&gt;&lt;profiles&gt; 一样简单。但是在 maven 中定义 docker 配置文件默认不会做任何事情,也许看看 maven.apache.org/guides/introduction/…baeldung.com/maven-profiles 更好地理解它

标签: spring-boot docker jenkins-pipeline pom.xml


【解决方案1】:

您只是缺少 pom.xml 中的 profiles 部分

<profiles>
    <profile>
        <id>docker</id>
    </profile>
</profiles>

【讨论】:

    猜你喜欢
    • 2020-01-06
    • 1970-01-01
    • 2013-07-10
    • 2015-03-27
    • 2014-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-08
    相关资源
    最近更新 更多