1

为了在成功部署工件的 docker 映像后促进构建,我们必须执行如下 curl 操作:

curl -k -I -u usr:pw -X POST https://company.com/artifactory/api/docker... - H "Content-Type: application/json" -d '{"targetRepo":"project-release","dockerRepository":"project/sample","tag":"1.0.0","copy":"false"}'

使用 Maven 尝试此操作时,请使用 exec 插件:

...
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>exec-maven-plugin</artifactId>
          <version>1.2</version>
          <executions>
            <execution>
              <id>promote-image</id>
              <phase>deploy</phase>
              <goals>
                <goal>exec</goal>
              </goals>
              <configuration>
                <executable>curl</executable>
                <arguments>
                  <argument>-k</argument>
                  <argument>-i</argument>
                  <argument>-u ${USER}:{PWD}</argument>
                  <argument>-X POST https://company.com/artifactory/api/docker/docker-local/v2/promote</argument>
                  <argument>-H "Content-Type: application/json"</argument>
                  <argument>-d &apos;{&quot;targetRepo&quot;:&quot;${docker.repository.release}&quot;,&quot;dockerRepository&quot;:&quot;${docker.image.prefix}/${project.artifactId}&quot;,&quot;tag&quot;:&quot;${project.version}&quot;,&quot;copy&quot;:&quot;false&quot;}&apos;</argument>
                </arguments>
              </configuration>
            </execution>
          </executions>
        </plugin>
...

但这导致 CI​​ 的构建失败,原因如下:

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:exec (promote-image) on project myproject: Execution promote-image of goal org.codehaus.mojo:exec-maven-plugin:1.2:exec failed: Can't handle single and double quotes in same argument -> [Help 1]

我认为这是因为 -d '" - 那怎么解决?

4

1 回答 1

1

首先我认为你需要像这样声明你的论点,看看会发生什么:

<plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>1.2</version>
      <executions>
        <execution>
          <id>promote-image</id>
          <phase>deploy</phase>
          <goals>
            <goal>exec</goal>
          </goals>
          <configuration>
            <executable>curl</executable>
            <arguments>
              <argument>-k</argument>
              <argument>-i</argument>
              <argument>-u</argument> 
              <argument>${USER}:{PWD}</argument>
              <argument>-X</argument> 
              <argument>POST</argument> 
              <argument>-H</argument>
              <argument>"Content-Type: application/json"</argument>
              <argument>-d</argument>
              <argument>&apos;{&quot;targetRepo&quot;:&quot;${docker.repository.release}&quot;,&quot;dockerRepository&quot;:&quot;${docker.image.prefix}/${project.artifactId}&quot;,&quot;tag&quot;:&quot;${project.version}&quot;,&quot;copy&quot;:&quot;false&quot;}&apos;</argument>
              <argument>https://company.com/artifactory/api/docker/docker-local/v2/promote</argument>
            </arguments>
          </configuration>
        </execution>
      </executions>
    </plugin>
于 2019-01-22T10:53:25.207 回答