1

To promote a build after successful deployment of an docker image of artifactory, we have to do a curl like this:

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"}'

When trying this with maven use the exec plugin:

...
        <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>
...

But this is leading to a broken build on CI with the reason:

[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]

I assume this is because -d '" - how could that be solved?

MemLeak
  • 4,456
  • 4
  • 45
  • 84
  • I'm not sure if I get you right, I've encoded the -d '{"targetRepo part and I'm still hitting the issue... – MemLeak Mar 23 '18 at 16:54
  • Ah sorry, my bad. I confused the -H and -d. You could try using only double-quotes and escaping it. Like `-d "{\"targetRepo...` i.e. the encoded form of `-d "{\"targetRepo...` – Vasan Mar 23 '18 at 16:55
  • I was able to curl without escaping or transforming my quotes: `-d {"request":{"method":"ANY","urlPattern":"/user-service/.*"},"response":{"proxyBaseUrl":"http://localhost:${service.http.port}"}}` – Basil Nov 15 '18 at 23:00

1 Answers1

1

first i think you need to declare your argument like this and see what happen :

<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>