Skip to content

[JENKINS-53866] Ability to specify imageName to tag and push #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,19 @@ class Docker implements Serializable {
}
}

public void tag(String tagName = parsedId.tag, boolean force = true) {
public void tag(String tagName = parsedId.tag, boolean force = true, String imageName = parsedId.userAndRepo) {
docker.node {
def taggedImageName = toQualifiedImageName(parsedId.userAndRepo + ':' + tagName)
def taggedImageName = toQualifiedImageName(imageName + ':' + tagName)
docker.script."${docker.shell()}" "docker tag ${id} ${taggedImageName}"
return taggedImageName;
}
}

public void push(String tagName = parsedId.tag, boolean force = true) {
public void push(String tagName = parsedId.tag, boolean force = true, String imageName = parsedId.userAndRepo) {
docker.node {
// The image may have already been tagged, so the tagging may be a no-op.
// That's ok since tagging is cheap.
def taggedImageName = tag(tagName, force)
def taggedImageName = tag(tagName, force, imageName)
docker.script."${docker.shell()}" "docker push ${taggedImageName}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,19 @@ private static void grep(File dir, String text, String prefix, Set<String> match
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" try { sh 'docker rmi busybox:test' } catch (Exception e) {}\n" +
" try { sh 'docker rmi busybox:test my.registry.com/busybox:test' } catch (Exception e) {}\n" +
" def busybox = docker.image('busybox');\n" +
" busybox.pull();\n" +
" // tag it\n" +
" busybox.tag('test', /* ignored but to test that the argument is accepted */false);\n" +
" // assert that the tag exists\n" +
" sh 'docker inspect busybox:test'\n" +
" // retag it\n" +
" busybox.tag('test');\n" +
" busybox.tag('test');\n" +
" // retag it with new image name\n" +
" busybox.tag('test', /* ignored but to test that the argument is accepted */ false, 'my.registry.com/busybox');\n" +
" // assert that the tag exists\n" +
" sh 'docker inspect my.registry.com/busybox:test'\n" +
"}", true));
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
}
Expand Down