本文整理匯總了Java中org.jenkinsci.lib.configprovider.model.Config類的典型用法代碼示例。如果您正苦於以下問題:Java Config類的具體用法?Java Config怎麽用?Java Config使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Config類屬於org.jenkinsci.lib.configprovider.model包,在下文中一共展示了Config類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testDefaultJenkinsFile
import org.jenkinsci.lib.configprovider.model.Config; //導入依賴的package包/類
@Test
public void testDefaultJenkinsFile() throws Exception {
GlobalConfigFiles globalConfigFiles = r.jenkins.getExtensionList(GlobalConfigFiles.class).get(GlobalConfigFiles.class);
ConfigFileStore store = globalConfigFiles.get();
Config config = new GroovyScript("Jenkinsfile", "Jenkinsfile", "",
"semaphore 'wait'; node {checkout scm; echo readFile('file')}");
store.save(config);
sampleGitRepo.init();
sampleGitRepo.write("file", "initial content");
sampleGitRepo.git("commit", "--all", "--message=flow");
WorkflowMultiBranchProject mp = r.jenkins.createProject(PipelineMultiBranchDefaultsProject.class, "p");
mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleGitRepo.toString(), "", "*", "", false),
new DefaultBranchPropertyStrategy(new BranchProperty[0])));
WorkflowJob p = PipelineMultiBranchDefaultsProjectTest.scheduleAndFindBranchProject(mp, "master");
SemaphoreStep.waitForStart("wait/1", null);
WorkflowRun b1 = p.getLastBuild();
assertNotNull(b1);
assertEquals(1, b1.getNumber());
SemaphoreStep.success("wait/1", null);
r.assertLogContains("initial content", r.waitForCompletion(b1));
}
示例2: create
import org.jenkinsci.lib.configprovider.model.Config; //導入依賴的package包/類
@Override
public FlowExecution create(FlowExecutionOwner handle, TaskListener listener, List<? extends Action> actions) throws Exception {
Jenkins jenkins = Jenkins.getInstance();
if (jenkins == null) {
throw new IllegalStateException("inappropriate context");
}
Queue.Executable exec = handle.getExecutable();
if (!(exec instanceof WorkflowRun)) {
throw new IllegalStateException("inappropriate context");
}
ConfigFileStore store = GlobalConfigFiles.get();
if (store != null) {
Config config = store.getById(PipelineBranchDefaultsProjectFactory.SCRIPT);
if (config != null) {
return new CpsFlowDefinition(config.content, false).create(handle, listener, actions);
}
}
throw new IllegalArgumentException("Default " + PipelineBranchDefaultsProjectFactory.SCRIPT + " not found. Check configuration.");
}
示例3: testDefaultJenkinsFileLoadFromWorkspace
import org.jenkinsci.lib.configprovider.model.Config; //導入依賴的package包/類
@Test
public void testDefaultJenkinsFileLoadFromWorkspace() throws Exception {
GlobalConfigFiles globalConfigFiles = r.jenkins.getExtensionList(GlobalConfigFiles.class).get(GlobalConfigFiles.class);
ConfigFileStore store = globalConfigFiles.get();
Config config = new GroovyScript("Jenkinsfile", "Jenkinsfile", "",
"semaphore 'wait'; node {checkout scm; load 'Jenkinsfile'}");
store.save(config);
sampleGitRepo.init();
sampleGitRepo.write("Jenkinsfile", "echo readFile('file')");
sampleGitRepo.git("add", "Jenkinsfile");
sampleGitRepo.write("file", "initial content");
sampleGitRepo.git("commit", "--all", "--message=flow");
WorkflowMultiBranchProject mp = r.jenkins.createProject(PipelineMultiBranchDefaultsProject.class, "p");
mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleGitRepo.toString(), "", "*", "", false),
new DefaultBranchPropertyStrategy(new BranchProperty[0])));
WorkflowJob p = PipelineMultiBranchDefaultsProjectTest.scheduleAndFindBranchProject(mp, "master");
SemaphoreStep.waitForStart("wait/1", null);
WorkflowRun b1 = p.getLastBuild();
assertNotNull(b1);
assertEquals(1, b1.getNumber());
SemaphoreStep.success("wait/1", null);
r.assertLogContains("initial content", r.waitForCompletion(b1));
}
示例4: doFillMavenSettingsConfigItems
import org.jenkinsci.lib.configprovider.model.Config; //導入依賴的package包/類
@Restricted(NoExternalUse.class) // Only for UI calls
public ListBoxModel doFillMavenSettingsConfigItems(@AncestorInPath ItemGroup context) {
ListBoxModel r = new ListBoxModel();
r.add("--- Use system default settings or file path ---",null);
for (Config config : ConfigFiles.getConfigsInContext(context, MavenSettingsConfigProvider.class)) {
r.add(config.name, config.id);
}
return r;
}
示例5: doFillGlobalMavenSettingsConfigItems
import org.jenkinsci.lib.configprovider.model.Config; //導入依賴的package包/類
@Restricted(NoExternalUse.class) // Only for UI calls
public ListBoxModel doFillGlobalMavenSettingsConfigItems(@AncestorInPath ItemGroup context) {
ListBoxModel r = new ListBoxModel();
r.add("--- Use system default settings or file path ---",null);
for (Config config : ConfigFiles.getConfigsInContext(context, GlobalMavenSettingsConfigProvider.class)) {
r.add(config.name, config.id);
}
return r;
}
示例6: configFile
import org.jenkinsci.lib.configprovider.model.Config; //導入依賴的package包/類
@Issue("JENKINS-27152")
@Test public void configFile() throws Exception {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
DockerTestUtil.assumeDocker();
ConfigProvider configProvider = story.j.jenkins.getExtensionList(ConfigProvider.class).get(CustomConfig.CustomConfigProvider.class);
String id = configProvider.getProviderId() + "myfile";
Config config = new CustomConfig(id, "My File", "", "some-content");
configProvider.save(config);
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" withDockerContainer('ubuntu') {\n" +
" wrap([$class: 'ConfigFileBuildWrapper', managedFiles: [[fileId: '" + config.id + "', variable: 'FILE']]]) {\n" +
" sh 'cat $FILE'\n" +
" }\n" +
" }\n" +
" wrap([$class: 'ConfigFileBuildWrapper', managedFiles: [[fileId: '" + config.id + "', variable: 'FILE']]]) {\n" +
" withDockerContainer('ubuntu') {\n" +
" sh 'tr \"a-z\" \"A-Z\" < $FILE'\n" +
" }\n" +
" }\n" +
"}", true));
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
story.j.assertLogContains("some-content", b);
story.j.assertLogContains("SOME-CONTENT", b);
}
});
}
示例7: settingsFromConfig
import org.jenkinsci.lib.configprovider.model.Config; //導入依賴的package包/類
/**
* Reads the config file from Config File Provider, expands the credentials and stores it in a file on the temp
* folder to use it with the maven wrapper script
*
* @param mavenSettingsConfigId config file id from Config File Provider
* @param mavenSettingsFile path to write te content to
* @param credentials
* @return the {@link FilePath} to the settings file
* @throws AbortException in case of error
*/
private void settingsFromConfig(String mavenSettingsConfigId, FilePath mavenSettingsFile, @Nonnull Collection<Credentials> credentials) throws AbortException {
Config c = ConfigFiles.getByIdOrNull(build, mavenSettingsConfigId);
if (c == null) {
throw new AbortException("Could not find the Maven settings.xml config file id:" + mavenSettingsConfigId + ". Make sure it exists on Managed Files");
}
if (StringUtils.isBlank(c.content)) {
throw new AbortException("Could not create Maven settings.xml config file id:" + mavenSettingsConfigId + ". Content of the file is empty");
}
MavenSettingsConfig mavenSettingsConfig;
if (c instanceof MavenSettingsConfig) {
mavenSettingsConfig = (MavenSettingsConfig) c;
} else {
mavenSettingsConfig = new MavenSettingsConfig(c.id, c.name, c.comment, c.content, MavenSettingsConfig.isReplaceAllDefault, null);
}
try {
// JENKINS-43787 handle null
final List<ServerCredentialMapping> serverCredentialMappings = Objects.firstNonNull(mavenSettingsConfig.getServerCredentialMappings(), Collections.<ServerCredentialMapping>emptyList());
final Map<String, StandardUsernameCredentials> resolvedCredentials = CredentialsHelper.resolveCredentials(build, serverCredentialMappings);
credentials.addAll(resolvedCredentials.values());
String mavenSettingsFileContent;
if (resolvedCredentials.isEmpty()) {
mavenSettingsFileContent = mavenSettingsConfig.content;
console.println("[withMaven] use Maven settings.xml '" + mavenSettingsConfig.id + "' with NO Maven servers credentials provided by Jenkins");
} else {
List<String> tempFiles = new ArrayList<String>();
mavenSettingsFileContent = CredentialsHelper.fillAuthentication(mavenSettingsConfig.content, mavenSettingsConfig.isReplaceAll, resolvedCredentials, tempBinDir, tempFiles);
console.println("[withMaven] use Maven settings.xml '" + mavenSettingsConfig.id + "' with Maven servers credentials provided by Jenkins " +
"(replaceAll: " + mavenSettingsConfig.isReplaceAll + "): " +
Joiner.on(", ").skipNulls().join(Iterables.transform(resolvedCredentials.entrySet(), new MavenServerToCredentialsMappingToStringFunction())));
}
mavenSettingsFile.write(mavenSettingsFileContent, getComputer().getDefaultCharset().name());
} catch (Exception e) {
throw new IllegalStateException("Exception injecting Maven settings.xml " + mavenSettingsConfig.id +
" during the build: " + build + ": " + e.getMessage(), e);
}
}
示例8: globalSettingsFromConfig
import org.jenkinsci.lib.configprovider.model.Config; //導入依賴的package包/類
/**
* Reads the global config file from Config File Provider, expands the credentials and stores it in a file on the temp
* folder to use it with the maven wrapper script
*
* @param mavenGlobalSettingsConfigId global config file id from Config File Provider
* @param mavenGlobalSettingsFile path to write te content to
* @param credentials
* @return the {@link FilePath} to the settings file
* @throws AbortException in case of error
*/
private void globalSettingsFromConfig(String mavenGlobalSettingsConfigId, FilePath mavenGlobalSettingsFile, Collection<Credentials> credentials) throws AbortException {
Config c = ConfigFiles.getByIdOrNull(build, mavenGlobalSettingsConfigId);
if (c == null) {
throw new AbortException("Could not find the Maven global settings.xml config file id:" + mavenGlobalSettingsFile + ". Make sure it exists on Managed Files");
}
if (StringUtils.isBlank(c.content)) {
throw new AbortException("Could not create Maven global settings.xml config file id:" + mavenGlobalSettingsFile + ". Content of the file is empty");
}
GlobalMavenSettingsConfig mavenGlobalSettingsConfig;
if (c instanceof GlobalMavenSettingsConfig) {
mavenGlobalSettingsConfig = (GlobalMavenSettingsConfig) c;
} else {
mavenGlobalSettingsConfig = new GlobalMavenSettingsConfig(c.id, c.name, c.comment, c.content, MavenSettingsConfig.isReplaceAllDefault, null);
}
try {
// JENKINS-43787 handle null
final List<ServerCredentialMapping> serverCredentialMappings = Objects.firstNonNull(mavenGlobalSettingsConfig.getServerCredentialMappings(), Collections.<ServerCredentialMapping>emptyList());
final Map<String, StandardUsernameCredentials> resolvedCredentials = CredentialsHelper.resolveCredentials(build, serverCredentialMappings);
credentials.addAll(resolvedCredentials.values());
String mavenGlobalSettingsFileContent;
if (resolvedCredentials.isEmpty()) {
mavenGlobalSettingsFileContent = mavenGlobalSettingsConfig.content;
console.println("[withMaven] use Maven global settings.xml '" + mavenGlobalSettingsConfig.id + "' with NO Maven servers credentials provided by Jenkins");
} else {
List<String> tempFiles = new ArrayList<String>();
mavenGlobalSettingsFileContent = CredentialsHelper.fillAuthentication(mavenGlobalSettingsConfig.content, mavenGlobalSettingsConfig.isReplaceAll, resolvedCredentials, tempBinDir, tempFiles);
console.println("[withMaven] use Maven global settings.xml '" + mavenGlobalSettingsConfig.id + "' with Maven servers credentials provided by Jenkins " +
"(replaceAll: " + mavenGlobalSettingsConfig.isReplaceAll + "): " +
Joiner.on(", ").skipNulls().join(Iterables.transform(resolvedCredentials.entrySet(), new MavenServerToCredentialsMappingToStringFunction())));
}
mavenGlobalSettingsFile.write(mavenGlobalSettingsFileContent, getComputer().getDefaultCharset().name());
LOGGER.log(Level.FINE, "Created global config file {0}", new Object[]{mavenGlobalSettingsFile});
} catch (Exception e) {
throw new IllegalStateException("Exception injecting Maven settings.xml " + mavenGlobalSettingsConfig.id +
" during the build: " + build + ": " + e.getMessage(), e);
}
}