42
42
import static org .junit .Assert .assertNotNull ;
43
43
44
44
public class FromFingerprintStepTest {
45
- @ Rule
46
- public RestartableJenkinsRule story = new RestartableJenkinsRule ();
45
+ @ Rule public RestartableJenkinsRule story = new RestartableJenkinsRule ();
47
46
48
- /**
49
- * Test quotation marks in --build-arg parameters
50
- */
51
- @ Test
52
- public void buildWithFROMArgs ()
53
- throws Exception {
47
+ /**
48
+ * Test quotation marks in --build-arg parameters
49
+ */
50
+ @ Test public void buildWithFROMArgs () throws Exception {
51
+ assertBuild ( "prj-simple" ,
52
+ script ( "--build-arg IMAGE_TO_UPDATE=hello-world:latest" ));
54
53
55
- assertBuild ("prj-simple " ,
56
- script ("--build-arg IMAGE_TO_UPDATE=hello-world:latest" ));
54
+ assertBuild ("prj-singlequotes-in-build-arg---aroundValue " ,
55
+ script ("--build-arg IMAGE_TO_UPDATE=\\ ' hello-world:latest\\ ' " ));
57
56
58
- assertBuild ("prj-singlequotes -in-build-arg---aroundValue" ,
59
- script ("--build-arg IMAGE_TO_UPDATE=\\ ' hello-world:latest\\ ' " ));
57
+ assertBuild ("prj-dobulequotes -in-build-arg---aroundValue" ,
58
+ script ("--build-arg IMAGE_TO_UPDATE=\" hello-world:latest\" " ));
60
59
61
- assertBuild ("prj-dobulequotes -in-build-arg---aroundValue " ,
62
- script ("--build-arg IMAGE_TO_UPDATE=\" hello-world:latest\" " ));
60
+ assertBuild ("prj-singlequotes -in-build-arg---aroundAll " ,
61
+ script ("--build-arg \\ ' IMAGE_TO_UPDATE=hello-world:latest\\ ' " ));
63
62
64
- assertBuild ("prj-singlequotes-in-build-arg---aroundAll" ,
65
- script ("--build-arg \\ 'IMAGE_TO_UPDATE=hello-world:latest\\ '" ));
63
+ assertBuild ("prj-doublequotes-in-build-arg---aroundAll" ,
64
+ script ("--build-arg \" IMAGE_TO_UPDATE=hello-world:latest\" " ));
65
+ }
66
66
67
- assertBuild ("prj-doublequotes-in-build-arg---aroundAll" ,
68
- script ("--build-arg \" IMAGE_TO_UPDATE=hello-world:latest\" " ));
69
- }
67
+ private static String script (String buildArg ) {
68
+ String dockerfile = "" +
69
+ "ARG IMAGE_TO_UPDATE\\ n" +
70
+ "FROM ${IMAGE_TO_UPDATE}\\ n" ;
71
+ String fullBuildArgs = buildArg + " buildWithFROMArgs" ;
70
72
71
- private static String script (String buildArg ) {
72
- String dockerfile = ""
73
- + "ARG IMAGE_TO_UPDATE\\ n"
74
- + "FROM ${IMAGE_TO_UPDATE}\\ n" ;
75
- String fullBuildArgs = buildArg + " buildWithFROMArgs" ;
73
+ String script = "node {\n " +
74
+ " sh 'mkdir buildWithFROMArgs'\n " +
75
+ " writeFile file: 'buildWithFROMArgs/Dockerfile', text: '" + dockerfile + "'\n " +
76
+ " def built = docker.build 'from-with-arg', '" + fullBuildArgs + "'\n " +
77
+ " echo \" built ${built.id}\" \n " +
78
+ "}" ;
76
79
77
- String script = "node {\n "
78
- + " sh 'mkdir buildWithFROMArgs'\n "
79
- + " writeFile file: 'buildWithFROMArgs/Dockerfile', text: '" + dockerfile + "'\n "
80
- + " def built = docker.build 'from-with-arg', '" + fullBuildArgs + "'\n "
81
- + " echo \" built ${built.id}\" \n "
82
- + "}" ;
80
+ return script ;
81
+ }
83
82
84
- return script ;
85
- }
83
+ private void assertBuild (final String projectName , final String piplineCode ) throws Exception {
84
+ story .addStep (new Statement () {
85
+ @ Override
86
+ public void evaluate () throws Throwable {
87
+ assumeDocker ();
86
88
87
- private void assertBuild (final String projectName , final String piplineCode )
88
- throws Exception {
89
- story .addStep (new Statement () {
90
- @ Override
91
- public void evaluate ()
92
- throws Throwable {
93
- assumeDocker ();
89
+ WorkflowJob p = story .j .jenkins .createProject (WorkflowJob .class , projectName );
90
+ p .setDefinition (new CpsFlowDefinition (piplineCode , true ));
91
+ WorkflowRun b = story .j .assertBuildStatusSuccess (p .scheduleBuild2 (0 ));
92
+ DockerClient client = new DockerClient (new LocalLauncher (StreamTaskListener .NULL ), null , null );
93
+ String ancestorImageId = client .inspect (new EnvVars (), "hello-world" , ".Id" );
94
+ story .j .assertLogContains ("built from-with-arg" , b );
95
+ story .j .assertLogContains (ancestorImageId .replaceFirst ("^sha256:" , "" ).substring (0 , 12 ), b );
96
+ Fingerprint f = DockerFingerprints .of (ancestorImageId );
97
+ assertNotNull (f );
98
+ DockerDescendantFingerprintFacet descendantFacet = f .getFacet (DockerDescendantFingerprintFacet .class );
99
+ assertNotNull (descendantFacet );
100
+ }
101
+ });
102
+ }
94
103
95
- WorkflowJob p = story .j .jenkins .createProject (WorkflowJob .class , projectName );
96
- p .setDefinition (new CpsFlowDefinition (piplineCode , true ));
97
- WorkflowRun b = story .j .assertBuildStatusSuccess (p .scheduleBuild2 (0 ));
98
- DockerClient client = new DockerClient (new LocalLauncher (StreamTaskListener .NULL ), null , null );
99
- String ancestorImageId = client .inspect (new EnvVars (), "hello-world" , ".Id" );
100
- story .j .assertLogContains ("built from-with-arg" , b );
101
- story .j .assertLogContains (ancestorImageId .replaceFirst ("^sha256:" , "" ).substring (0 , 12 ), b );
102
- Fingerprint f = DockerFingerprints .of (ancestorImageId );
103
- assertNotNull (f );
104
- DockerDescendantFingerprintFacet descendantFacet = f .getFacet (
105
- DockerDescendantFingerprintFacet .class );
106
- assertNotNull (descendantFacet );
107
- }
108
- });
109
- }
110
-
111
- }
104
+ }
0 commit comments