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

The following examples show how to use com.cloudbees.hudson.plugins.folder.Folder#createProject() . 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 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 2
Source File: GerritWebHookTriggerTest.java    From gerrit-code-review-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void gerritWebHookShouldTriggerMultiBranchPipelineProjectWithFolder() throws Exception {
  Folder f = j.jenkins.createProject(Folder.class, "folder");
  WorkflowMultiBranchProject mp = f.createProject(WorkflowMultiBranchProject.class, projectName);
  mp.getSourcesList().add(new BranchSource(getGerritSCMSource()));

  assertEquals(httpStatusOfPostGerritEventBodyToWebhookURI(), HttpServletResponse.SC_OK);
  j.waitUntilNoActivity();

  assertEquals(Result.SUCCESS, mp.getIndexing().getResult());
}
 
Example 3
Source File: GogsWebHookPluginsTest.java    From gogs-webhook-plugin with MIT License 5 votes vote down vote up
@Test
public void testCloudBeesFolder() throws Exception {
    Folder folder = createFolder(FOLDERNAME);

    FreeStyleProject project = folder.createProject(FreeStyleProject.class, PROJECTNAME);

    Job job = GogsUtils.find(FOLDERNAME + "/" + PROJECTNAME, Job.class);
    assertEquals("Couldn't find " + FOLDERNAME + "/" + PROJECTNAME, job, project);
}
 
Example 4
Source File: WithAWSStepTest.java    From pipeline-aws-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testStepWithFolderCredentials() throws Exception {

	String folderCredentialsId = "folders-aws-creds";

	// Create a folder with credentials in its store
	Folder folder = jenkinsRule.jenkins.createProject(Folder.class, "folder" + jenkinsRule.jenkins.getItems().size());
	CredentialsStore folderStore = this.getFolderStore(folder);
	StandardUsernamePasswordCredentials inFolderCredentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL,
																								  folderCredentialsId, "test-folder-creds", "folder-aws-access-key-id", "folder-aws-secret-access-key");
	folderStore.addCredentials(Domain.global(), inFolderCredentials);
	SystemCredentialsProvider.getInstance().save();

	List<String> credentialIds = new ArrayList<>();
	credentialIds.add(folderCredentialsId);

	WorkflowJob job = folder.createProject(WorkflowJob.class, "testStepWithFolderCredentials");
	job.setDefinition(new CpsFlowDefinition(""
													+ "node {\n"
													+ "  withAWS (credentials: '" + folderCredentialsId + "') {\n"
													+ "    echo 'It works!'\n"
													+ "  }\n"
													+ "}\n", true)
	);
	jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));

}
 
Example 5
Source File: WithAWSStepTest.java    From pipeline-aws-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testStepWithAWSFolderCredentials() throws Exception {

	String folderCredentialsId = "folders-aws-creds";

	// Create a folder with credentials in its store
	Folder folder = jenkinsRule.jenkins.createProject(Folder.class, "folder" + jenkinsRule.jenkins.getItems().size());
	CredentialsStore folderStore = this.getFolderStore(folder);
	AmazonWebServicesCredentials amazonWebServicesCredentials = new AWSCredentialsImpl(CredentialsScope.GLOBAL,
			folderCredentialsId, "global-aws-access-key-id", "global-aws-secret-access-key", "Aws-Description",
			"Arn::Something:or:Other", "12345678");
	folderStore.addCredentials(Domain.global(), amazonWebServicesCredentials);
	SystemCredentialsProvider.getInstance().save();

	List<String> credentialIds = new ArrayList<>();
	credentialIds.add(folderCredentialsId);

	WorkflowJob job = folder.createProject(WorkflowJob.class, "testStepWithAWSFolderCredentials");
	job.setDefinition(new CpsFlowDefinition(""
			+ "node {\n"
			+ "  withAWS (credentials: '" + folderCredentialsId + "') {\n"
			+ "    echo 'It works!'\n"
			+ "  }\n"
			+ "}\n", true)
	);
	WorkflowRun workflowRun = job.scheduleBuild2(0).get();
	jenkinsRule.waitForCompletion(workflowRun);
	jenkinsRule.assertBuildStatus(Result.FAILURE, workflowRun);
	jenkinsRule.assertLogContains("The security token included in the request is invalid.", workflowRun);
	jenkinsRule.assertLogContains("Constructing AWS Credentials", workflowRun);

}
 
Example 6
Source File: WithAWSStepTest.java    From pipeline-aws-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testStepWithAWSIamMFAFolderCredentials() throws Exception {

	String folderCredentialsId = "folders-aws-creds";

	// Create a folder with credentials in its store
	Folder folder = jenkinsRule.jenkins.createProject(Folder.class, "folder" + jenkinsRule.jenkins.getItems().size());
	CredentialsStore folderStore = this.getFolderStore(folder);
	AmazonWebServicesCredentials amazonWebServicesCredentials = new AWSCredentialsImpl(CredentialsScope.GLOBAL,
			folderCredentialsId, "global-aws-access-key-id", "global-aws-secret-access-key", "Aws-Description",
			"Arn::Something:or:Other", "12345678");
	folderStore.addCredentials(Domain.global(), amazonWebServicesCredentials);
	SystemCredentialsProvider.getInstance().save();

	List<String> credentialIds = new ArrayList<>();
	credentialIds.add(folderCredentialsId);

	WorkflowJob job = folder.createProject(WorkflowJob.class, "testStepWithAWSIamMFAFolderCredentials");
	job.setDefinition(new CpsFlowDefinition(""
			+ "node {\n"
			+ "  withAWS (credentials: '" + folderCredentialsId + "', iamMfaToken: '1234567') {\n"
			+ "    echo 'It works!'\n"
			+ "  }\n"
			+ "}\n", true)
	);
	WorkflowRun workflowRun = job.scheduleBuild2(0).get();
	jenkinsRule.waitForCompletion(workflowRun);
	jenkinsRule.assertBuildStatus(Result.FAILURE, workflowRun);
	jenkinsRule.assertLogContains("The security token included in the request is invalid.", workflowRun);
	jenkinsRule.assertLogContains("Constructing AWS Credentials", workflowRun);
	jenkinsRule.assertLogContains("utilizing MFA Token", workflowRun);

}
 
Example 7
Source File: WithAWSStepTest.java    From pipeline-aws-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testListCredentials() throws Exception {
	Folder folder = jenkinsRule.jenkins.createProject(Folder.class, "folder" + jenkinsRule.jenkins.getItems().size());
	CredentialsStore folderStore = this.getFolderStore(folder);
	StandardUsernamePasswordCredentials folderCredentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL,
			"folder-creds", "test-creds", "aws-access-key-id", "aws-secret-access-key");
	StandardUsernamePasswordCredentials globalCredentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL,
			"global-creds", "test-creds", "aws-access-key-id", "aws-secret-access-key");

	folderStore.addCredentials(Domain.global(), folderCredentials);
	SystemCredentialsProvider.getInstance().getCredentials().add(globalCredentials);
	SystemCredentialsProvider.getInstance().save();

	WorkflowJob job = folder.createProject(WorkflowJob.class, "testStepWithFolderCredentials");
	final WithAWSStep.DescriptorImpl descriptor = jenkinsRule.jenkins.getDescriptorByType(WithAWSStep.DescriptorImpl.class);

	// 3 options: Root credentials, folder credentials and "none"
	ListBoxModel list = descriptor.doFillCredentialsItems(job);
	Assert.assertEquals(3, list.size());

	StandardUsernamePasswordCredentials systemCredentials = new UsernamePasswordCredentialsImpl(CredentialsScope.SYSTEM,
			"system-creds", "test-creds", "aws-access-key-id", "aws-secret-access-key");
	SystemCredentialsProvider.getInstance().getCredentials().add(systemCredentials);

	// Still 3 options: Root credentials, folder credentials and "none"
	list = descriptor.doFillCredentialsItems(job);
	Assert.assertEquals(3, list.size());
}
 
Example 8
Source File: WithAWSStepTest.java    From pipeline-aws-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testListAWSCredentials() throws Exception {

	Folder folder = jenkinsRule.jenkins.createProject(Folder.class, "folder" + jenkinsRule.jenkins.getItems().size());
	CredentialsStore folderStore = this.getFolderStore(folder);
	AmazonWebServicesCredentials amazonWebServicesCredentials = new AWSCredentialsImpl(CredentialsScope.GLOBAL,
			"test-aws-creds", "global-aws-access-key-id", "global-aws-secret-access-key", "Aws-Description",
			"Arn::Something:or:Other", "12345678");
	AmazonWebServicesCredentials globalAmazonWebServicesCredentials = new AWSCredentialsImpl(CredentialsScope.GLOBAL,
			"global-test-aws-creds", "global-aws-access-key-id", "global-aws-secret-access-key", "Aws-Description",
			"Arn::Something:or:Other", "12345678");

	folderStore.addCredentials(Domain.global(), amazonWebServicesCredentials);
	SystemCredentialsProvider.getInstance().getCredentials().add(globalAmazonWebServicesCredentials);
	SystemCredentialsProvider.getInstance().save();

	WorkflowJob job = folder.createProject(WorkflowJob.class, "testStepWithFolderCredentials");
	final WithAWSStep.DescriptorImpl descriptor = jenkinsRule.jenkins.getDescriptorByType(WithAWSStep.DescriptorImpl.class);

	// 3 options: Root credentials, folder credentials and "none"
	ListBoxModel list = descriptor.doFillCredentialsItems(job);
	Assert.assertEquals(3, list.size());

	StandardUsernamePasswordCredentials systemCredentials = new UsernamePasswordCredentialsImpl(CredentialsScope.SYSTEM,
			"system-creds", "test-creds", "aws-access-key-id", "aws-secret-access-key");
	SystemCredentialsProvider.getInstance().getCredentials().add(systemCredentials);

	// Still 3 options: Root credentials, folder credentials and "none"
	list = descriptor.doFillCredentialsItems(job);
	Assert.assertEquals(3, list.size());
}
 
Example 9
Source File: GitHubNotificationPipelineStepTest.java    From pipeline-githubnotify-step-plugin with MIT License 5 votes vote down vote up
@Test
public void buildWithFolderCredentials() throws Exception {

    GitHubBuilder ghb = PowerMockito.mock(GitHubBuilder.class);
    PowerMockito.when(ghb.withProxy(Matchers.<Proxy>anyObject())).thenReturn(ghb);
    PowerMockito.when(ghb.withOAuthToken(anyString(), anyString())).thenReturn(ghb);
    PowerMockito.whenNew(GitHubBuilder.class).withNoArguments().thenReturn(ghb);
    GitHub gh = PowerMockito.mock(GitHub.class);
    PowerMockito.when(ghb.build()).thenReturn(gh);
    PowerMockito.when(gh.isCredentialValid()).thenReturn(true);
    GHRepository repo = PowerMockito.mock(GHRepository.class);
    GHUser user = PowerMockito.mock(GHUser.class);
    GHCommit commit = PowerMockito.mock(GHCommit.class);
    PowerMockito.when(user.getRepository(anyString())).thenReturn(repo);
    PowerMockito.when(gh.getUser(anyString())).thenReturn(user);
    PowerMockito.when((repo.getCommit(anyString()))).thenReturn(commit);

    Folder f = jenkins.jenkins.createProject(Folder.class, "folder" + jenkins.jenkins.getItems().size());
    CredentialsStore folderStore = getFolderStore(f);
    folderStore.addCredentials(Domain.global(),
            new DummyCredentials(CredentialsScope.GLOBAL, "user", "password"));

    WorkflowJob p = f.createProject(WorkflowJob.class, "p");
    p.setDefinition(new CpsFlowDefinition(
            "githubNotify account: 'raul-arabaolaza', context: 'ATH Results', " +
                    "credentialsId: 'dummy', description: 'All tests are OK', " +
                    "repo: 'acceptance-test-harness', sha: '0b5936eb903d439ac0c0bf84940d73128d5e9487', " +
                    "status: 'SUCCESS', targetUrl: 'http://www.cloudbees.com'"
    ));
    WorkflowRun b1 = p.scheduleBuild2(0).waitForStart();
    jenkins.assertBuildStatus(Result.SUCCESS, jenkins.waitForCompletion(b1));
}
 
Example 10
Source File: FolderRoleBenchmark.java    From folder-auth-plugin with MIT License 4 votes vote down vote up
@Override
public void setup() throws Exception {
    Jenkins jenkins = getJenkins();
    jenkins.setSecurityRealm(new JenkinsRule().createDummySecurityRealm());

    Set<GlobalRole> globalRoles = ImmutableSet.of((
            new GlobalRole("ADMIN", wrapPermissions(Jenkins.ADMINISTER), Collections.singleton("admin"))),
        new GlobalRole("read", wrapPermissions(Jenkins.READ), Collections.singleton("authenticated"))
    );

    Set<FolderRole> folderRoles = new HashSet<>();

    Random random = new Random(100L);

    // create the folders
    for (int i = 0; i < 10; i++) {
        String topFolderName = "TopFolder" + i;
        Folder folder = jenkins.createProject(Folder.class, topFolderName);

        Set<String> users = new HashSet<>();
        for (int k = 0; k < random.nextInt(5); k++) {
            users.add("user" + random.nextInt(100));
        }

        FolderRole userRole = new FolderRole(topFolderName, wrapPermissions(Item.READ, Item.DISCOVER),
            Collections.singleton(topFolderName), users);

        folderRoles.add(userRole);

        for (int j = 0; j < 5; j++) {
            Folder bottom = folder.createProject(Folder.class, "BottomFolder" + j);

            Set<String> maintainers = new HashSet<>(2);
            maintainers.add("user" + random.nextInt(100));
            maintainers.add("user" + random.nextInt(100));

            FolderRole maintainerRole = new FolderRole(bottom.getFullName(),
                wrapPermissions(Item.READ, Item.DISCOVER, Item.CREATE),
                Collections.singleton(topFolderName), maintainers);

            Set<String> admin = Collections.singleton("user" + random.nextInt(100));

            FolderRole folderAdminRole = new FolderRole(bottom.getFullName(), wrapPermissions(Item.READ, Item.DISCOVER,
                Item.CONFIGURE, Item.CREATE), Collections.singleton(topFolderName), admin);
            folderRoles.add(maintainerRole);
            folderRoles.add(folderAdminRole);

            for (int k = 0; k < 5; k++) {
                bottom.createProject(FreeStyleProject.class, "Project" + k);
            }
        }
    }

    jenkins.setAuthorizationStrategy(new FolderBasedAuthorizationStrategy(globalRoles, folderRoles,
        Collections.emptySet()));
}
 
Example 11
Source File: RoleStrategyTest.java    From configuration-as-code-plugin with MIT License 4 votes vote down vote up
@Test
@Issue("Issue #48")
@ConfiguredWithCode("RoleStrategy1.yml")
public void shouldReadRolesCorrectly() throws Exception {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    User admin = User.getById("admin", false);
    User user1 = User.getById("user1", false);
    User user2 = User.getById("user2", true);
    Computer agent1 = j.jenkins.getComputer("agent1");
    Computer agent2 = j.jenkins.getComputer("agent2");
    Folder folderA = j.jenkins.createProject(Folder.class, "A");
    FreeStyleProject jobA1 = folderA.createProject(FreeStyleProject.class, "1");
    Folder folderB = j.jenkins.createProject(Folder.class, "B");
    folderB.createProject(FreeStyleProject.class, "2");

    AuthorizationStrategy s = j.jenkins.getAuthorizationStrategy();
    assertThat("Authorization Strategy has been read incorrectly",
            s, instanceOf(RoleBasedAuthorizationStrategy.class));
    RoleBasedAuthorizationStrategy rbas = (RoleBasedAuthorizationStrategy) s;

    Map<Role, Set<String>> globalRoles = rbas.getGrantedRoles(RoleBasedAuthorizationStrategy.GLOBAL);
    assertThat(globalRoles.size(), equalTo(2));

    // Admin has configuration access
    assertHasPermission(admin, j.jenkins, Jenkins.ADMINISTER, Jenkins.READ);
    assertHasPermission(user1, j.jenkins, Jenkins.READ);
    assertHasNoPermission(user1, j.jenkins, Jenkins.ADMINISTER);

    // Folder A is restricted to admin
    assertHasPermission(admin, folderA, Item.CONFIGURE);
    assertHasPermission(user1, folderA, Item.READ, Item.DISCOVER);
    assertHasNoPermission(user1, folderA, Item.CONFIGURE, Item.DELETE, Item.BUILD);

    // But they have access to jobs in Folder A
    assertHasPermission(admin, folderA, Item.CONFIGURE, Item.CANCEL);
    assertHasPermission(user1, jobA1, Item.READ, Item.DISCOVER, Item.CONFIGURE, Item.BUILD, Item.DELETE);
    assertHasPermission(user2, jobA1, Item.READ, Item.DISCOVER, Item.CONFIGURE, Item.BUILD, Item.DELETE);
    assertHasNoPermission(user1, folderA, Item.CANCEL);

    // FolderB is editable by user2, but he cannot delete it
    assertHasPermission(user2, folderB, Item.READ, Item.DISCOVER, Item.CONFIGURE, Item.BUILD);
    assertHasNoPermission(user2, folderB, Item.DELETE);
    assertHasNoPermission(user1, folderB, Item.CONFIGURE, Item.BUILD, Item.DELETE);

    // Only user1 can run on agent1, but he still cannot configure it
    assertHasPermission(admin, agent1, Computer.CONFIGURE, Computer.DELETE, Computer.BUILD);
    assertHasPermission(user1, agent1, Computer.BUILD);
    assertHasNoPermission(user1, agent1, Computer.CONFIGURE, Computer.DISCONNECT);

    // Same user still cannot build on agent2
    assertHasNoPermission(user1, agent2, Computer.BUILD);
}
 
Example 12
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 13
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);
    }
}