为了在成功部署工件的 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 '{"targetRepo":"${docker.repository.release}","dockerRepository":"${docker.image.prefix}/${project.artifactId}","tag":"${project.version}","copy":"false"}'</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 '" - 那怎么解决?