-
-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathXLDeployJenkinsFileITest.java
More file actions
90 lines (74 loc) · 3.59 KB
/
XLDeployJenkinsFileITest.java
File metadata and controls
90 lines (74 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* Copyright (c) 2014, XebiaLabs B.V., All rights reserved.
* <p>
* <p>
* The XL Release plugin for Jenkins is licensed under the terms of the GPLv2
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most XebiaLabs Libraries.
* There are special exceptions to the terms and conditions of the GPLv2 as it is applied to
* this software, see the FLOSS License Exception
* <https://github.com/jenkinsci/xlrelease-plugin/blob/master/LICENSE>.
* <p>
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation; version 2
* of the License.
* <p>
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth
* Floor, Boston, MA 02110-1301 USA
*/
package com.xebialabs.deployit.ci;
import hudson.model.Result;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.LocalData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Objects;
public class XLDeployJenkinsFileITest {
private static final String ADMIN_CREDENTIAL = "admin_credential";
private static final String ENV_XLD_HOST = "xlDeployIntegration.host";
private static final String ENV_XLD_USERNAME = "xlDeployIntegration.username";
private static final String ENV_XLD_PASSWORD = "xlDeployIntegration.password";
private static final String DEFAULT_HOST = "http://localhost:4516";
private static final String DEFAULT_USERNAME = "admin";
private static final String DEFAULT_PASSWORD = "admin";
private static String host;
private static String username;
private static String password;
private static final Logger logger = LoggerFactory.getLogger(XLDeployJenkinsFileITest.class);
@Rule
public JenkinsRule jenkins = new JenkinsRule();
@Before
public void before() {
host = System.getProperty(ENV_XLD_HOST) != null ? System.getProperty(ENV_XLD_HOST) : DEFAULT_HOST;
username = System.getProperty(ENV_XLD_USERNAME) != null ? System.getProperty(ENV_XLD_USERNAME) : DEFAULT_USERNAME;
password = System.getProperty(ENV_XLD_PASSWORD) != null ? System.getProperty(ENV_XLD_PASSWORD) : DEFAULT_PASSWORD;
}
@Test
@LocalData
public void shouldStartReleaseWithJenkinsFile() throws Exception {
WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "rest-o-rant-api");
job.setDefinition(new CpsFlowDefinition(getJenkinsFileScript(), true));
jenkins.assertBuildStatus(Result.SUCCESS, job.scheduleBuild2(0).get());
}
private String getJenkinsFileScript() throws IOException {
String jenkinsFile = "";
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
Files.copy(Paths.get(Objects.requireNonNull(getClass().getClassLoader().getResource("JenkinsFile")).getFile()), outputStream);
jenkinsFile = outputStream.toString();
}
return jenkinsFile;
}
}