[JIRA] (JENKINS-49677) Docker image tag based on hash of Dockerfile

2 views
Skip to first unread message

gavin.llewellyn@blackboard.com (JIRA)

unread,
Feb 21, 2018, 11:33:02 AM2/21/18
to jenkinsc...@googlegroups.com
Gavin Llewellyn created an issue
 
Jenkins / Bug JENKINS-49677
Docker image tag based on hash of Dockerfile
Issue Type: Bug Bug
Assignee: Andrew Bayer
Components: pipeline-model-definition-plugin
Created: 2018-02-21 16:32
Priority: Major Major
Reporter: Gavin Llewellyn

I've got a multi-branch declarative pipeline build job that uses 

agent { dockerfile true }

to set up a container for the build.  Multiple branches have an identical Dockerfile, but building an image produces different results, as the result also depends on other files in the repository.

We recently had a job that failed due to two branches building in parallel; after much head scratching we realised the same tag had been applied to both of the two docker images built, so one of the branches ended up being built inside a container based on the other branch's image.  Digging in to the code, I can see that the image tag is currently based on the hash of the Dockerfile - I think this is flawed, as identical Dockerfiles do not necessarily produce the same output.

I can think of two other options:

  1. Use a tag based on the (full) job name
  2. Use a randomly generated tag

I believe Docker is already pretty clever about re-using cached intermediate images, so I don't think these changes will have a significant impact on subsequent image build times, even if a random tag is used.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

andrew.bayer@gmail.com (JIRA)

unread,
Feb 21, 2018, 11:40:03 AM2/21/18
to jenkinsc...@googlegroups.com
Andrew Bayer started work on Bug JENKINS-49677
 
Change By: Andrew Bayer
Status: Open In Progress

andrew.bayer@gmail.com (JIRA)

unread,
Feb 21, 2018, 11:42:02 AM2/21/18
to jenkinsc...@googlegroups.com
Andrew Bayer commented on Bug JENKINS-49677
 
Re: Docker image tag based on hash of Dockerfile

Gonna go with Utils.stringToSHA1(currentBuild.fullProjectName + "\n" + readFile(dockerfile)) - currentBuild.fullProjectName gets the full job name, so that should do the trick.

andrew.bayer@gmail.com (JIRA)

unread,
Feb 21, 2018, 11:43:02 AM2/21/18
to jenkinsc...@googlegroups.com

andrew.bayer@gmail.com (JIRA)

unread,
Feb 21, 2018, 11:46:02 AM2/21/18
to jenkinsc...@googlegroups.com

gavin.llewellyn@blackboard.com (JIRA)

unread,
Feb 21, 2018, 12:03:03 PM2/21/18
to jenkinsc...@googlegroups.com

Looks good to me, thanks for the quick response!

scm_issue_link@java.net (JIRA)

unread,
Feb 27, 2018, 11:14:02 AM2/27/18
to jenkinsc...@googlegroups.com

Code changed in jenkins
User: Andrew Bayer
Path:
pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/DockerPipelineFromDockerfileScript.groovy
http://jenkins-ci.org/commit/pipeline-model-definition-plugin/6c5c09eb278b490d8544624e3c1f897e7e139ed4
Log:
[FIXED JENKINS-49677] Include full project name in hash for Dockerfile tag

andrew.bayer@gmail.com (JIRA)

unread,
Feb 27, 2018, 11:25:05 AM2/27/18
to jenkinsc...@googlegroups.com
 

This'll be in the upcoming Declarative 1.2.8 release.

Change By: Andrew Bayer
Status: In Review Resolved
Resolution: Fixed

anthony@madetech.com (JIRA)

unread,
Jun 12, 2018, 12:55:02 PM6/12/18
to jenkinsc...@googlegroups.com
Anthony King commented on Bug JENKINS-49677
 
Re: Docker image tag based on hash of Dockerfile

Hi,

I've encountered this issue when dockerfiles run when running a parallel pipeline within the same project.

 

For now, our workaround is to include a comment in one.

An example is located here:

https://github.com/cybojenix/jenkins-docker-parallel/tree/6737a3964d689f1e3b9f514dd4de788c44a93999

 

bitwiseman@gmail.com (JIRA)

unread,
Oct 22, 2019, 11:25:40 PM10/22/19
to jenkinsc...@googlegroups.com
Liam Newman closed an issue as Fixed
 

Bulk closing resolved issues.

Change By: Liam Newman
Status: Resolved Closed
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages