2

We have a Jenkinsfile that kicks off a docker-compose command. Jenkinsfile bit looks like this

  sh("""docker-compose build \
    --no-cache \
    --build-arg DATE=${sh([returnStdout: true, script: "date -u +%Y%m%dT%H%M%SZ  | tr -d '\n'"])} \
    --build-arg VERSION=${sh([returnStdout: true, script: "git describe --tags --always"])} \
    --build-arg SHA=${sh([returnStdout: true, script: "git rev-parse HEAD"])}""")

But when I run the build in Jenkins I see it logging out the command as

docker-compose build --no-cache --build-arg DATE=20190411T142851Z --build-arg VERSION=470a670

These are being passed in to set LABEL items in a Dockerfile. I've tried using Docker and setting the labels manually, but it also truncates afte rthe second label.

It will use the first two or three, regardless of what they are. Anything after those labels (or build-args for docker-compose) is chopped off and not used.

For example, the docker command used was this

  sh("""docker build \
    --no-cache \
    --label com.<company>.name="Some stuff" \
    --label com.<company>.build-date=${sh([returnStdout: true, script: "date -u +%Y%m%dT%H%M%SZ  | tr -d '\n'"])} \
    --label com.<company>.version=${sh([returnStdout: true, script: "git describe --tags --always"])} \
    --label com.<company>.repo-sha=${sh([returnStdout: true, script: "git rev-parse HEAD"])} \
    --tag ${folderName} \
    .""")

and that led to this error

docker build --no-cache --label com.<company>.name='Some stuff' --label com.<company>.build-date=20190410T192516Z --label com.<company>.version=9bfbd1b
"docker build" requires exactly 1 argument.

It cut off the tag and the period for the directory.

Neal
  • 127
  • 1
  • 2
  • 9
  • Update: Looks like it's an issue with the sh() command. Digging in to where we get that from. I did a println of the full command and it showed up. – Neal Apr 11 '19 at 15:51
  • Sadly it's even dumber than that. Posting an answer. – Neal Apr 11 '19 at 16:04
  • 1
    Yeah never mind: you are right. I read through the question too quickly. This could be helpful for you: https://stackoverflow.com/questions/47392267/running-nested-commands-in-jenkins-pipeline-shell/47394132#47394132 – Matthew Schuchard Apr 11 '19 at 16:06
  • Oh well, I'll take this as a learning experience. – Neal Apr 11 '19 at 16:09

1 Answers1

0

Turns out I'm a moron.

git describe --tags --always returns a new line, so I needed | tr -d '\n' in that as well. I didn't write the original date command and should have looked at that earlier.

gmc
  • 3,910
  • 2
  • 31
  • 44
Neal
  • 127
  • 1
  • 2
  • 9