【发布时间】:2018-09-02 10:13:55
【问题描述】:
为了在成功部署工件的 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 '" - 这怎么解决?
【问题讨论】:
-
我不确定我是否正确,我已经对
-d '{"targetRepo 部分进行了编码,但我仍然遇到问题...... -
对不起,我的错。我混淆了-H和-d。您可以尝试仅使用双引号并将其转义。像
-d &quot;{&#92;&quot;targetRepo...即-d "{\"targetRepo...的编码形式 -
我能够在不转义或转换引号的情况下卷曲:
<argument>-d {"request":{"method":"ANY","urlPattern":"/user-service/.*"},"response":{"proxyBaseUrl":"http://localhost:${service.http.port}"}}</argument>
标签: maven curl maven-exec-plugin