Search in sources :

Example 1 with BranchSpec

use of hudson.plugins.git.BranchSpec in project workflow-cps-plugin by jenkinsci.

the class CpsScmFlowDefinitionTest method usingParameter.

@Issue("JENKINS-28447")
@Test
public void usingParameter() throws Exception {
    sampleRepo.init();
    sampleRepo.write("flow.groovy", "echo 'version one'");
    sampleRepo.git("add", "flow.groovy");
    sampleRepo.git("commit", "--message=one");
    sampleRepo.git("tag", "one");
    sampleRepo.write("flow.groovy", "echo 'version two'");
    sampleRepo.git("commit", "--all", "--message=two");
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    CpsScmFlowDefinition def = new CpsScmFlowDefinition(new GitSCM(Collections.singletonList(new UserRemoteConfig(sampleRepo.fileUrl(), null, null, null)), Collections.singletonList(new BranchSpec("${VERSION}")), false, Collections.<SubmoduleConfig>emptyList(), null, null, Collections.<GitSCMExtension>emptyList()), "flow.groovy");
    // TODO SCMFileSystem.of cannot pick up build parameters
    def.setLightweight(false);
    p.setDefinition(def);
    p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("VERSION", "master")));
    r.assertLogContains("version two", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
    r.assertLogContains("version one", r.assertBuildStatusSuccess(p.scheduleBuild2(0, new ParametersAction(new StringParameterValue("VERSION", "one")))));
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) BranchSpec(hudson.plugins.git.BranchSpec) StringParameterValue(hudson.model.StringParameterValue) SubmoduleConfig(hudson.plugins.git.SubmoduleConfig) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) ParametersAction(hudson.model.ParametersAction) GitSCM(hudson.plugins.git.GitSCM) UserRemoteConfig(hudson.plugins.git.UserRemoteConfig) GitSCMExtension(hudson.plugins.git.extensions.GitSCMExtension) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 2 with BranchSpec

use of hudson.plugins.git.BranchSpec in project gitea-plugin by jenkinsci.

the class GiteaCreateSCMEvent method isMatch.

/**
 * {@inheritDoc}
 */
@Override
public boolean isMatch(@NonNull SCM scm) {
    URIish uri;
    try {
        uri = new URIish(getPayload().getRepository().getHtmlUrl());
    } catch (URISyntaxException e) {
        return false;
    }
    String ref = getPayload().getRef();
    ref = ref.startsWith(Constants.R_HEADS) ? ref.substring(Constants.R_HEADS.length()) : ref;
    if (scm instanceof GitSCM) {
        GitSCM git = (GitSCM) scm;
        if (git.getExtensions().get(IgnoreNotifyCommit.class) != null) {
            return false;
        }
        for (RemoteConfig repository : git.getRepositories()) {
            for (URIish remoteURL : repository.getURIs()) {
                if (GitStatus.looselyMatches(uri, remoteURL)) {
                    for (BranchSpec branchSpec : git.getBranches()) {
                        if (branchSpec.getName().contains("$")) {
                            // If the branchspec is parametrized, always run the polling
                            return true;
                        } else {
                            if (branchSpec.matches(repository.getName() + "/" + ref)) {
                                return true;
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : URIish(org.eclipse.jgit.transport.URIish) BranchSpec(hudson.plugins.git.BranchSpec) IgnoreNotifyCommit(hudson.plugins.git.extensions.impl.IgnoreNotifyCommit) URISyntaxException(java.net.URISyntaxException) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) GitSCM(hudson.plugins.git.GitSCM)

Example 3 with BranchSpec

use of hudson.plugins.git.BranchSpec in project gitea-plugin by jenkinsci.

the class GiteaPushSCMEvent method isMatch.

/**
 * {@inheritDoc}
 */
@Override
public boolean isMatch(@NonNull SCM scm) {
    URIish uri;
    try {
        uri = new URIish(getPayload().getRepository().getHtmlUrl());
    } catch (URISyntaxException e) {
        return false;
    }
    String ref = getPayload().getRef();
    ref = ref.startsWith(Constants.R_HEADS) ? ref.substring(Constants.R_HEADS.length()) : ref;
    if (scm instanceof GitSCM) {
        GitSCM git = (GitSCM) scm;
        if (git.getExtensions().get(IgnoreNotifyCommit.class) != null) {
            return false;
        }
        for (RemoteConfig repository : git.getRepositories()) {
            for (URIish remoteURL : repository.getURIs()) {
                if (GitStatus.looselyMatches(uri, remoteURL)) {
                    for (BranchSpec branchSpec : git.getBranches()) {
                        if (branchSpec.getName().contains("$")) {
                            // If the branchspec is parametrized, always run the polling
                            return true;
                        } else {
                            if (branchSpec.matches(repository.getName() + "/" + ref)) {
                                return true;
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : URIish(org.eclipse.jgit.transport.URIish) BranchSpec(hudson.plugins.git.BranchSpec) IgnoreNotifyCommit(hudson.plugins.git.extensions.impl.IgnoreNotifyCommit) URISyntaxException(java.net.URISyntaxException) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) GitSCM(hudson.plugins.git.GitSCM)

Example 4 with BranchSpec

use of hudson.plugins.git.BranchSpec in project gitlab-branch-source-plugin by Argelbargel.

the class GitLabSCMMergeRequestHead method getBranchSpecs.

@Nonnull
@Override
List<BranchSpec> getBranchSpecs() {
    if (!merge) {
        return super.getBranchSpecs();
    }
    List<BranchSpec> branches = new ArrayList<>(2);
    branches.addAll(super.getBranchSpecs());
    branches.add(new BranchSpec(targetBranch.getRef()));
    return branches;
}
Also used : BranchSpec(hudson.plugins.git.BranchSpec) ArrayList(java.util.ArrayList) Nonnull(javax.annotation.Nonnull)

Example 5 with BranchSpec

use of hudson.plugins.git.BranchSpec in project memory-map-plugin by Praqma.

the class TestUtils method configureGit.

public static FreeStyleProject configureGit(FreeStyleProject project, String branchName, String repository) throws IOException {
    List<UserRemoteConfig> repos = Collections.singletonList(new UserRemoteConfig(repository, null, null, null));
    GitSCM gitSCM = new GitSCM(repos, Collections.singletonList(new BranchSpec(branchName)), false, Collections.<SubmoduleConfig>emptyList(), null, null, Collections.EMPTY_LIST);
    project.setScm(gitSCM);
    return project;
}
Also used : BranchSpec(hudson.plugins.git.BranchSpec) UserRemoteConfig(hudson.plugins.git.UserRemoteConfig) GitSCM(hudson.plugins.git.GitSCM)

Aggregations

BranchSpec (hudson.plugins.git.BranchSpec)5 GitSCM (hudson.plugins.git.GitSCM)4 UserRemoteConfig (hudson.plugins.git.UserRemoteConfig)2 IgnoreNotifyCommit (hudson.plugins.git.extensions.impl.IgnoreNotifyCommit)2 URISyntaxException (java.net.URISyntaxException)2 RemoteConfig (org.eclipse.jgit.transport.RemoteConfig)2 URIish (org.eclipse.jgit.transport.URIish)2 ParametersAction (hudson.model.ParametersAction)1 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)1 StringParameterDefinition (hudson.model.StringParameterDefinition)1 StringParameterValue (hudson.model.StringParameterValue)1 SubmoduleConfig (hudson.plugins.git.SubmoduleConfig)1 GitSCMExtension (hudson.plugins.git.extensions.GitSCMExtension)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)1 Test (org.junit.Test)1 Issue (org.jvnet.hudson.test.Issue)1