private void round2() throws Exception { sampleRepo.git("checkout", "master"); sampleRepo.write("Jenkinsfile", "// more"); sampleRepo.git("commit", "--all", "--message=master-2"); sampleRepo.git("checkout", "newfeature"); sampleRepo.write("Jenkinsfile", "// more"); sampleRepo.git("commit", "--all", "--message=newfeature-2"); sampleRepo.git("checkout", "release"); sampleRepo.write("Jenkinsfile", "// more"); sampleRepo.git("commit", "--all", "--message=release-2"); sampleRepo.notifyCommit(r); }
private void round3() throws Exception { sampleRepo.git("checkout", "master"); sampleRepo.write("Jenkinsfile", "// yet more"); sampleRepo.git("commit", "--all", "--message=master-3"); sampleRepo.git("checkout", "newfeature"); sampleRepo.write("Jenkinsfile", "// yet more"); sampleRepo.git("commit", "--all", "--message=newfeature-3"); sampleRepo.git("checkout", "release"); sampleRepo.write("Jenkinsfile", "// yet more"); sampleRepo.git("commit", "--all", "--message=release-3"); sampleRepo.notifyCommit(r); }
private void round1() throws Exception { sampleRepo.init(); sampleRepo.write("Jenkinsfile", ""); sampleRepo.git("add", "Jenkinsfile"); sampleRepo.git("commit", "--message=init"); sampleRepo.git("checkout", "-b", "newfeature"); sampleRepo.write("Jenkinsfile", "// newfeature"); sampleRepo.git("commit", "--all", "--message=newfeature"); sampleRepo.git("checkout", "-b", "release", "master"); sampleRepo.write("Jenkinsfile", "// release"); sampleRepo.git("commit", "--all", "--message=release"); }
protected void prepRepoWithJenkinsfileAndOtherFiles(String pipelineName, Map<String, String> otherFiles) throws Exception { sampleRepo.init(); sampleRepo.write("Jenkinsfile", pipelineSourceFromResources(pipelineName)); sampleRepo.git("add", "Jenkinsfile"); for (Map.Entry<String, String> otherFile : otherFiles.entrySet()) { if (otherFile != null) { sampleRepo.write(otherFile.getValue(), fileContentsFromResources(otherFile.getKey())); sampleRepo.git("add", otherFile.getValue()); } } sampleRepo.git("commit", "--message=files"); }
@Test public void fromDockerfileNoArgs() throws Exception { assumeDocker(); sampleRepo.write("Dockerfile", "FROM ubuntu:14.04\n\nRUN echo 'HI THERE' > /hi-there\n\n"); sampleRepo.git("init"); sampleRepo.git("add", "Dockerfile"); sampleRepo.git("commit", "--message=Dockerfile"); expect("fromDockerfileNoArgs") .logContains("[Pipeline] { (foo)", "The answer is 42", "HI THERE") .go(); }
@Test public void fromAlternateDockerfile() throws Exception { assumeDocker(); sampleRepo.write("Dockerfile.alternate", "FROM ubuntu:14.04\n\nRUN echo 'HI THERE' > /hi-there\n\n"); sampleRepo.git("init"); sampleRepo.git("add", "Dockerfile.alternate"); sampleRepo.git("commit", "--message=Dockerfile"); expect("fromAlternateDockerfile") .logContains("[Pipeline] { (foo)", "The answer is 42", "-v /tmp:/tmp", "HI THERE") .go(); }
@Test public void fromDockerfile() throws Exception { assumeDocker(); sampleRepo.write("Dockerfile", "FROM ubuntu:14.04\n\nRUN echo 'HI THERE' > /hi-there\n\n"); sampleRepo.git("init"); sampleRepo.git("add", "Dockerfile"); sampleRepo.git("commit", "--message=Dockerfile"); expect("fromDockerfile") .logContains("[Pipeline] { (foo)", "The answer is 42", "-v /tmp:/tmp", "HI THERE") .go(); }
@Test public void additionalDockerBuildArgs() throws Exception { assumeDocker(); sampleRepo.write("Dockerfile", "FROM ubuntu:14.04\n\nARG someArg=thisArgHere\n\nRUN echo \"hi there, $someArg\" > /hi-there\n\n"); sampleRepo.git("init"); sampleRepo.git("add", "Dockerfile"); sampleRepo.git("commit", "--message=Dockerfile"); expect("additionalDockerBuildArgs") .logContains("[Pipeline] { (foo)", "The answer is 42", "-v /tmp:/tmp", "hi there, thisOtherArg") .logNotContains("hi there, thisArgHere") .go(); }
@Issue("JENKINS-41668") @Test public void fromDockerfileInOtherDir() throws Exception { assumeDocker(); sampleRepo.write("subdir/Dockerfile", "FROM ubuntu:14.04\n\nRUN echo 'HI THERE' > /hi-there\n\n"); sampleRepo.git("init"); sampleRepo.git("add", "subdir/Dockerfile"); sampleRepo.git("commit", "--message=Dockerfile"); expect("fromDockerfileInOtherDir") .logContains("[Pipeline] { (foo)", "The answer is 42", "-v /tmp:/tmp", "HI THERE") .go(); }
@Issue("JENKINS-42286") @Test public void dirSepInDockerfileName() throws Exception { assumeDocker(); sampleRepo.write("subdir/Dockerfile", "FROM ubuntu:14.04\n\nRUN echo 'HI THERE' > /hi-there\n\n"); sampleRepo.git("init"); sampleRepo.git("add", "subdir/Dockerfile"); sampleRepo.git("commit", "--message=Dockerfile"); expect("fromDockerfileInOtherDir") .logContains("[Pipeline] { (foo)", "The answer is 42", "-v /tmp:/tmp", "HI THERE") .go(); }
@Issue("JENKINS-47106") @Test public void dockerPullLocalImage() throws Exception { assumeDocker(); sampleRepo.write("Dockerfile", "FROM ubuntu:14.04\n\nRUN echo 'HI THERE' > /hi-there\n\n"); sampleRepo.git("init"); sampleRepo.git("add", "Dockerfile"); sampleRepo.git("commit", "--message=Dockerfile"); expect("dockerPullLocalImage") .logContains("[Pipeline] { (in built image)", "The answer is 42", "-v /tmp:/tmp", "HI THERE", "Maven home: /usr/share/maven") .go(); }
@Test public void whenChangelog() throws Exception { //TODO JENKINS-46086 First time build always skips the changelog final ExpectationsBuilder builder = expect("when/changelog", "changelog") .logContains("Hello", "Stage \"Two\" skipped due to when conditional", "Warning, empty changelog. Probably because this is the first build.") .logNotContains("Dull World"); builder.go(); builder.resetForNewRun(Result.SUCCESS); sampleRepo.write("something.txt", "//fake file"); sampleRepo.git("add", "something.txt"); sampleRepo.git("commit", "-m", "Some title that we don't care about\n\nSome explanation\n[DEPENDENCY] some-app#45"); builder.logContains("Hello", "Dull World") .logNotContains("Stage \"Two\" skipped due to when conditional", "Warning, empty changelog.") .go(); }
@Override public void evaluate() throws Throwable { sampleGitRepo.init(); sampleGitRepo.write("Jenkinsfile", "node {checkout scm; echo readFile('file')}"); sampleGitRepo.write("file", "some content"); sampleGitRepo.git("add", "Jenkinsfile"); sampleGitRepo.git("commit", "--all", "--message=flow"); WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsScmFlowDefinition(new GitStep(sampleGitRepo.toString()).createSCM(), "Jenkinsfile")); WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0)); story.j.assertLogContains("some content", b); } });
@Issue("JENKINS-46547") @Test public void multiplePipelinesExecutedInLibraryShouldFail() throws Exception { otherRepo.init(); otherRepo.write("vars/fromLib.groovy", pipelineSourceFromResources("libForMultiplePipelinesExecutedInLibrary")); otherRepo.git("add", "vars"); otherRepo.git("commit", "--message=init"); LibraryConfiguration firstLib = new LibraryConfiguration("from-lib", new SCMSourceRetriever(new GitSCMSource(null, otherRepo.toString(), "", "*", "", true))); GlobalLibraries.get().setLibraries(Arrays.asList(firstLib)); expect(Result.FAILURE, "pipelineDefinedInLibrary") .logContains("java.lang.IllegalStateException: Only one pipeline { ... } block can be executed in a single run") .go(); }
@Issue("JENKINS-40642") @Test public void libraryAnnotation() throws Exception { otherRepo.init(); otherRepo.write("vars/myecho.groovy", "def call() {echo 'something special'}"); otherRepo.write("vars/myecho.txt", "Says something very special!"); otherRepo.git("add", "vars"); otherRepo.git("commit", "--message=init"); GlobalLibraries.get().setLibraries(Collections.singletonList( new LibraryConfiguration("echo-utils", new SCMSourceRetriever(new GitSCMSource(null, otherRepo.toString(), "", "*", "", true))))); expect("libraryAnnotation") .logContains("something special") .go(); }
@Issue("JENKINS-46547") @Test public void pipelineDefinedInLibrary() throws Exception { otherRepo.init(); otherRepo.write("vars/fromLib.groovy", pipelineSourceFromResources("libForPipelineDefinedInLibrary")); otherRepo.git("add", "vars"); otherRepo.git("commit", "--message=init"); LibraryConfiguration firstLib = new LibraryConfiguration("from-lib", new SCMSourceRetriever(new GitSCMSource(null, otherRepo.toString(), "", "*", "", true))); GlobalLibraries.get().setLibraries(Arrays.asList(firstLib)); expect("pipelineDefinedInLibrary") .logContains("[Pipeline] { (One)", "[Pipeline] { (Two)") .logNotContains("World") .go(); }
@Override public void evaluate() throws Throwable { WorkflowJob p = story.j.jenkins.getItemByFullName("p/dev%2Fmain", WorkflowJob.class); assertNotNull(p); sampleRepo.git("commit", "--all", "--message=Flow"); sampleRepo.notifyCommit(story.j); WorkflowRun b2 = p.getLastBuild(); assertEquals(2, b2.getNumber()); story.j.assertLogContains("Branch=dev/main", b2); story.j.assertLogContains("workspace=dev_main", b2); verifyProject(p); } });
@Issue("JENKINS-31386") @Test public void nonMultibranch() throws Exception { sampleRepo.init(); sampleRepo.write("Jenkinsfile", "echo \"said ${readTrusted 'message'}\""); sampleRepo.write("message", "how do you do"); sampleRepo.git("add", "Jenkinsfile", "message"); sampleRepo.git("commit", "--all", "--message=defined"); WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); GitStep step = new GitStep(sampleRepo.toString()); p.setDefinition(new CpsScmFlowDefinition(step.createSCM(), "Jenkinsfile")); WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0)); r.assertLogContains("said how do you do", b); r.assertLogContains("Obtained message from git ", b); }
@Override public void evaluate() throws Throwable { sampleGitRepo.init(); sampleGitRepo.write("Jenkinsfile", "def _scm = scm; semaphore 'wait'; node {checkout _scm; echo readFile('file')}"); sampleGitRepo.write("file", "initial content"); sampleGitRepo.git("add", "Jenkinsfile"); sampleGitRepo.git("commit", "--all", "--message=flow"); WorkflowMultiBranchProject mp = story.j.jenkins.createProject(WorkflowMultiBranchProject.class, "p"); mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleGitRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0]))); WorkflowJob p = WorkflowMultiBranchProjectTest.scheduleAndFindBranchProject(mp, "master"); SemaphoreStep.waitForStart("wait/1", null); WorkflowRun b1 = p.getLastBuild(); assertNotNull(b1); } });