Java Code Examples for com.cloudbees.hudson.plugins.folder.Folder#addProperty()

The following examples show how to use com.cloudbees.hudson.plugins.folder.Folder#addProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeclarativeDockerUtilsTest.java    From docker-workflow-plugin with MIT License 6 votes vote down vote up
@Test
public void directParentNotSystem() throws Exception {
    GlobalConfig.get().setDockerLabel("config_docker");
    GlobalConfig.get().setRegistry(new DockerRegistryEndpoint("https://docker.registry", globalCred.getId()));
    Folder folder = j.createProject(Folder.class);
    getFolderStore(folder).addCredentials(Domain.global(), folderCred);
    folder.addProperty(new FolderConfig("folder_docker", "https://folder.registry", folderCred.getId()));
    expect("org/jenkinsci/plugins/docker/workflow/declarative/declarativeDockerConfig")
            .inFolder(folder)
            .runFromRepo(false)
            .logContains("Docker Label is: folder_docker",
                    "Registry URL is: https://folder.registry",
                    "Registry Creds ID is: " + folderCred.getId())
            .logNotContains("Docker Label is: config_docker",
                    "Registry URL is: https://docker.registry",
                    "Registry Creds ID is: " + globalCred.getId()).go();
}
 
Example 2
Source File: DeclarativeDockerUtilsTest.java    From docker-workflow-plugin with MIT License 6 votes vote down vote up
@Test
public void grandParentOverride() throws Exception {
    Folder grandParent = j.createProject(Folder.class);
    getFolderStore(grandParent).addCredentials(Domain.global(), grandParentCred);
    grandParent.addProperty(new FolderConfig("parent_docker", "https://parent.registry", grandParentCred.getId()));
    Folder parent = grandParent.createProject(Folder.class, "testParent"); //Can be static since grandParent should be unique
    getFolderStore(parent).addCredentials(Domain.global(), folderCred);
    parent.addProperty(new FolderConfig("folder_docker", "https://folder.registry", folderCred.getId()));

    expect("org/jenkinsci/plugins/docker/workflow/declarative/declarativeDockerConfig")
            .inFolder(parent)
            .runFromRepo(false)
            .logContains("Docker Label is: folder_docker",
                    "Registry URL is: https://folder.registry",
                    "Registry Creds ID is: " + folderCred.getId())
            .logNotContains("Docker Label is: parent_docker",
                    "Registry URL is: https://parent.registry",
                    "Registry Creds ID is: " + grandParentCred.getId()).go();
}
 
Example 3
Source File: DeclarativeDockerUtilsTest.java    From docker-workflow-plugin with MIT License 5 votes vote down vote up
@Test
public void directParent() throws Exception {
    Folder folder = j.createProject(Folder.class);
    getFolderStore(folder).addCredentials(Domain.global(), folderCred);
    folder.addProperty(new FolderConfig("folder_docker", "https://folder.registry", folderCred.getId()));
    expect("org/jenkinsci/plugins/docker/workflow/declarative/declarativeDockerConfig")
            .inFolder(folder)
            .runFromRepo(false)
            .logContains("Docker Label is: folder_docker",
                    "Registry URL is: https://folder.registry",
                    "Registry Creds ID is: " + folderCred.getId()).go();
}
 
Example 4
Source File: DeclarativeDockerUtilsTest.java    From docker-workflow-plugin with MIT License 5 votes vote down vote up
@Test
public void withDefaults() throws Exception {
    Folder folder = j.createProject(Folder.class);
    getFolderStore(folder).addCredentials(Domain.global(), folderCred);
    getFolderStore(folder).addCredentials(Domain.global(), grandParentCred);
    folder.addProperty(new FolderConfig("folder_docker", "https://folder.registry", folderCred.getId()));
    expect("org/jenkinsci/plugins/docker/workflow/declarative/declarativeDockerConfigWithOverride")
            .inFolder(folder)
            .runFromRepo(false)
            .logContains("Docker Label is: other-label",
                    "Registry URL is: https://other.registry",
                    "Registry Creds ID is: " + grandParentCred.getId()).go();
}
 
Example 5
Source File: WithMavenStepOnMasterTest.java    From pipeline-maven-plugin with MIT License 4 votes vote down vote up
@Test
public void maven_global_settings_defined_through_folder_config_and_config_file_provider() throws Exception {

    String mavenGlobalSettings = "<?xml version='1.0' encoding='UTF-8'?>\n" +
            "<settings \n" +
            "        xmlns='http://maven.apache.org/SETTINGS/1.0.0'\n" +
            "        xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n" +
            "        xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd'>\n" +
            "    <servers>\n" +
            "       <server>\n" +
            "           <id>id-global-settings-test-from-config-file-provider-on-a-folder</id>\n" +
            "       </server>\n" +
            "    </servers>\n" +
            "</settings>\n";

    GlobalMavenSettingsConfig mavenGlobalSettingsConfig = new GlobalMavenSettingsConfig("maven-global-config-test-folder", "maven-global-config-test-folder", "",
        mavenGlobalSettings);

    String pipelineScript = "node () {\n" +
            "    writeFile file: 'pom.xml', text: '''<?xml version='1.0' encoding='UTF-8'?>\n" +
            "<project\n" +
            "        xmlns='http://maven.apache.org/POM/4.0.0' \n" +
            "        xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' \n" +
            "        xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd'>\n" +
            "    <modelVersion>4.0.0</modelVersion>\n" +
            "    <groupId>com.example</groupId>\n" +
            "    <artifactId>my-artifact</artifactId>\n" +
            "    <version>1.0.0-SNAPSHOT</version>\n" +
            "    <packaging>pom</packaging>\n" +
            "</project>'''\n" +
            "\n" +
            "    withMaven(maven: 'apache-maven-3.5.0') {\n" +
            "        sh 'mvn help:effective-settings'\n" +
            "    }\n" +
            "}\n";

    GlobalConfigFiles.get().save(mavenGlobalSettingsConfig);

    Folder folder = jenkinsRule.createProject(Folder.class, "folder");
    MavenConfigFolderOverrideProperty configOverrideProperty = new MavenConfigFolderOverrideProperty();
    configOverrideProperty.setOverride(true);
    configOverrideProperty.setGlobalSettings(new MvnGlobalSettingsProvider(mavenGlobalSettingsConfig.id));
    folder.addProperty(configOverrideProperty);

    try {
        WorkflowJob pipeline = folder.createProject(WorkflowJob.class,
            "build-on-master-with-maven-global-settings-defined-in-jenkins-global-config-with-config-file-provider");
        pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true));
        WorkflowRun build = jenkinsRule.assertBuildStatus(Result.SUCCESS, pipeline.scheduleBuild2(0));
        jenkinsRule.assertLogContains(
            "[withMaven] using overriden Maven global settings by folder 'folder'. Config File Provider maven global settings file 'maven-global-config-test-folder'",
            build);
        jenkinsRule.assertLogContains("<id>id-global-settings-test-from-config-file-provider-on-a-folder</id>", build);
    } finally {
        GlobalMavenConfig.get().setGlobalSettingsProvider(null);
        GlobalConfigFiles.get().remove(mavenGlobalSettingsConfig.id);
    }
}
 
Example 6
Source File: WithMavenStepOnMasterTest.java    From pipeline-maven-plugin with MIT License 4 votes vote down vote up
@Test
public void maven_settings_defined_through_folder_config_and_config_file_provider() throws Exception {

    String mavenSettings = "<?xml version='1.0' encoding='UTF-8'?>\n" +
            "<settings \n" +
            "        xmlns='http://maven.apache.org/SETTINGS/1.0.0'\n" +
            "        xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n" +
            "        xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd'>\n" +
            "    <servers>\n" +
            "       <server>\n" +
            "           <id>id-settings-test-through-config-file-provider-on-a-folder</id>\n" +
            "       </server>\n" +
            "    </servers>\n" +
            "</settings>\n";
    MavenSettingsConfig mavenSettingsConfig = new MavenSettingsConfig("maven-config-test-folder", "maven-config-test-folder", "", mavenSettings, false, null);

    String pipelineScript = "node () {\n" +
            "    writeFile file: 'pom.xml', text: '''<?xml version='1.0' encoding='UTF-8'?>\n" +
            "<project\n" +
            "        xmlns='http://maven.apache.org/POM/4.0.0' \n" +
            "        xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' \n" +
            "        xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd'>\n" +
            "    <modelVersion>4.0.0</modelVersion>\n" +
            "    <groupId>com.example</groupId>\n" +
            "    <artifactId>my-artifact</artifactId>\n" +
            "    <version>1.0.0-SNAPSHOT</version>\n" +
            "    <packaging>pom</packaging>\n" +
            "</project>'''\n" +
            "\n" +
            "    withMaven(maven: 'apache-maven-3.5.0') {\n" +
            "        sh 'mvn help:effective-settings'\n" +
            "    }\n" +
            "}\n";
    GlobalConfigFiles.get().save(mavenSettingsConfig);

    Folder folder = jenkinsRule.createProject(Folder.class, "folder");
    MavenConfigFolderOverrideProperty configOverrideProperty = new MavenConfigFolderOverrideProperty();
    configOverrideProperty.setOverride(true);
    GlobalMavenConfig globalMavenConfig = GlobalMavenConfig.get();
    configOverrideProperty.setGlobalSettings(globalMavenConfig.getGlobalSettingsProvider());
    configOverrideProperty.setSettings(new MvnSettingsProvider(mavenSettingsConfig.id));
    folder.addProperty(configOverrideProperty);

    try {
        WorkflowJob pipeline = folder.createProject(WorkflowJob.class, "build-on-master-with-maven-settings-defined-in-jenkins-global-config-with-config-file-provider");
        pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true));
        WorkflowRun build = jenkinsRule.assertBuildStatus(Result.SUCCESS, pipeline.scheduleBuild2(0));
        jenkinsRule.assertLogContains("[withMaven] using overriden Maven settings by folder 'folder'. Config File Provider maven settings file 'maven-config-test-folder'",
            build);
        jenkinsRule.assertLogContains("<id>id-settings-test-through-config-file-provider-on-a-folder</id>", build);
    } finally {
        configOverrideProperty.setOverride(false);
    }
}