Search in sources :

Example 26 with User

use of hudson.model.User in project hudson-2.x by hudson.

the class BaseBuildResultMail method createEmptyMail.

/**
     * Creates empty mail.
     *
     * @param build build.
     * @param listener listener.
     * @return empty mail.
     * @throws MessagingException exception if any.
     */
protected MimeMessage createEmptyMail(AbstractBuild<?, ?> build, BuildListener listener) throws MessagingException {
    MimeMessage msg = new HudsonMimeMessage(Mailer.descriptor().createSession());
    // TODO: I'd like to put the URL to the page in here,
    // but how do I obtain that?
    msg.setContent("", "text/plain");
    msg.setFrom(new InternetAddress(Mailer.descriptor().getAdminAddress()));
    msg.setSentDate(new Date());
    Set<InternetAddress> rcp = new LinkedHashSet<InternetAddress>();
    StringTokenizer tokens = new StringTokenizer(getRecipients());
    while (tokens.hasMoreTokens()) {
        String address = tokens.nextToken();
        if (address.startsWith("upstream-individuals:")) {
            // people who made a change in the upstream
            String projectName = address.substring("upstream-individuals:".length());
            AbstractProject up = Hudson.getInstance().getItemByFullName(projectName, AbstractProject.class);
            if (up == null) {
                listener.getLogger().println("No such project exist: " + projectName);
                continue;
            }
            includeCulpritsOf(up, build, listener, rcp);
        } else {
            // ordinary address
            try {
                rcp.add(new InternetAddress(address));
            } catch (AddressException e) {
                // report bad address, but try to send to other addresses
                e.printStackTrace(listener.error(e.getMessage()));
            }
        }
    }
    if (CollectionUtils.isNotEmpty(upstreamProjects)) {
        for (AbstractProject project : upstreamProjects) {
            includeCulpritsOf(project, build, listener, rcp);
        }
    }
    if (sendToIndividuals) {
        Set<User> culprits = build.getCulprits();
        if (debug)
            listener.getLogger().println("Trying to send e-mails to individuals who broke the build. sizeof(culprits)==" + culprits.size());
        rcp.addAll(buildCulpritList(listener, culprits));
    }
    msg.setRecipients(Message.RecipientType.TO, rcp.toArray(new InternetAddress[rcp.size()]));
    AbstractBuild<?, ?> pb = build.getPreviousBuild();
    if (pb != null) {
        MailMessageIdAction b = pb.getAction(MailMessageIdAction.class);
        if (b != null) {
            msg.setHeader("In-Reply-To", b.messageId);
            msg.setHeader("References", b.messageId);
        }
    }
    return msg;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InternetAddress(javax.mail.internet.InternetAddress) User(hudson.model.User) HudsonMimeMessage(hudson.tasks.HudsonMimeMessage) Date(java.util.Date) MailMessageIdAction(hudson.tasks.MailMessageIdAction) StringTokenizer(java.util.StringTokenizer) MimeMessage(javax.mail.internet.MimeMessage) HudsonMimeMessage(hudson.tasks.HudsonMimeMessage) AddressException(javax.mail.internet.AddressException) AbstractProject(hudson.model.AbstractProject)

Example 27 with User

use of hudson.model.User in project blueocean-plugin by jenkinsci.

the class GitScmTest method shouldGetForbiddenForBadCredentialIdOnUpdate2.

@Test
public void shouldGetForbiddenForBadCredentialIdOnUpdate2() throws IOException, UnirestException {
    User user = login();
    String mbp = createMbp(user);
    SystemCredentialsProvider.ProviderImpl system = ExtensionList.lookup(CredentialsProvider.class).get(SystemCredentialsProvider.ProviderImpl.class);
    CredentialsStore systemStore = system.getStore(j.getInstance());
    systemStore.addDomain(new Domain("domain1", null, null));
    Map<String, Object> resp = createCredentials(user, ImmutableMap.of("credentials", new ImmutableMap.Builder<String, Object>().put("password", "abcd").put("stapler-class", "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl").put("scope", "USER").put("domain", "blueocean-git-domain").put("description", "joe desc").put("$class", "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl").put("username", "joe").build()));
    String credentialId = (String) resp.get("id");
    Assert.assertNotNull(credentialId);
    put("/organizations/jenkins/pipelines/" + mbp + "/", ImmutableMap.of("name", mbp, "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineUpdateRequest", "scmConfig", ImmutableMap.of("uri", "git@github.com:vivek/capability-annotation.git", "credentialId", credentialId)), 400);
}
Also used : User(hudson.model.User) SystemCredentialsProvider(com.cloudbees.plugins.credentials.SystemCredentialsProvider) CredentialsStore(com.cloudbees.plugins.credentials.CredentialsStore) SystemCredentialsProvider(com.cloudbees.plugins.credentials.SystemCredentialsProvider) CredentialsProvider(com.cloudbees.plugins.credentials.CredentialsProvider) Domain(com.cloudbees.plugins.credentials.domains.Domain) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 28 with User

use of hudson.model.User in project blueocean-plugin by jenkinsci.

the class GitScmTest method shouldGetBadRequestForBadGitUriOnUpdate.

@Test
public void shouldGetBadRequestForBadGitUriOnUpdate() throws IOException, UnirestException {
    User user = login();
    String mbp = createMbp(user);
    new RequestBuilder(baseUrl).status(400).jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).put("/organizations/jenkins/pipelines/" + mbp + "/").data(ImmutableMap.of("name", mbp, "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineUpdateRequest", "scmConfig", ImmutableMap.of("uri", "/sdsd/sdsd/sdsd"))).build(Map.class);
}
Also used : User(hudson.model.User) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 29 with User

use of hudson.model.User in project blueocean-plugin by jenkinsci.

the class GitScmTest method shouldGetForbiddenForBadCredentialIdOnCreate1.

@Test
public void shouldGetForbiddenForBadCredentialIdOnCreate1() throws IOException, UnirestException {
    User user = login();
    Map resp = createCredentials(user, ImmutableMap.of("credentials", new ImmutableMap.Builder<String, Object>().put("privateKeySource", ImmutableMap.of("privateKey", "abcabc1212", "stapler-class", "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource")).put("passphrase", "ssh2").put("scope", "USER").put("domain", "blueocean-git-domain").put("description", "ssh2 desc").put("$class", "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey").put("username", "ssh2").build()));
    String credentialId = (String) resp.get("id");
    Assert.assertNotNull(credentialId);
    post("/organizations/jenkins/pipelines/", ImmutableMap.of("name", "demo", "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest", "scmConfig", ImmutableMap.of("uri", "git@github.com:vivek/capability-annotation.git", "credentialId", credentialId)), 400);
}
Also used : User(hudson.model.User) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 30 with User

use of hudson.model.User in project blueocean-plugin by jenkinsci.

the class GitScmTest method shouldGetForbiddenForBadCredentialIdOnCreate2.

@Test
public void shouldGetForbiddenForBadCredentialIdOnCreate2() throws IOException, UnirestException {
    User user = login();
    Map resp = createCredentials(user, ImmutableMap.of("credentials", new ImmutableMap.Builder<String, Object>().put("password", "abcd").put("stapler-class", "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl").put("scope", "USER").put("domain", "blueocean-git-domain").put("description", "joe desc").put("$class", "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl").put("username", "joe").build()));
    String credentialId = (String) resp.get("id");
    Assert.assertNotNull(credentialId);
    post("/organizations/jenkins/pipelines/", ImmutableMap.of("name", "demo", "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest", "scmConfig", ImmutableMap.of("uri", "git@github.com:vivek/capability-annotation.git", "credentialId", credentialId)), 400);
}
Also used : User(hudson.model.User) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Aggregations

User (hudson.model.User)48 Test (org.junit.Test)30 Map (java.util.Map)22 ImmutableMap (com.google.common.collect.ImmutableMap)21 PipelineBaseTest (io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest)11 Mailer (hudson.tasks.Mailer)8 Domain (com.cloudbees.plugins.credentials.domains.Domain)7 CredentialsStore (com.cloudbees.plugins.credentials.CredentialsStore)5 BlueOceanDomainRequirement (io.jenkins.blueocean.rest.impl.pipeline.credential.BlueOceanDomainRequirement)5 FreeStyleProject (hudson.model.FreeStyleProject)4 Job (hudson.model.Job)4 ServiceException (io.jenkins.blueocean.commons.ServiceException)4 List (java.util.List)4 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)3 Cause (hudson.model.Cause)3 IOException (java.io.IOException)3 OrganizationFolder (jenkins.branch.OrganizationFolder)3 Authentication (org.acegisecurity.Authentication)3 MockFolder (org.jvnet.hudson.test.MockFolder)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3