Skip to content

Cpappas/build jenkins #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 48 additions & 13 deletions src/main/groovy/4configureMailerPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
import java.util.logging.Logger
import net.sf.json.JSONObject
import net.sf.json.JSONException
import javax.servlet.http.HttpServletRequestWrapper

import jenkins.model.*
import hudson.tasks.Mailer
import org.kohsuke.stapler.StaplerRequest;
//import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.*;

@Grapes([
@Grab(group='org.yaml', module='snakeyaml', version='1.17')
@Grab(group='org.yaml', module='snakeyaml', version='1.17'),
@Grab(group='org.mockito', module='mockito-all', version='1.10.19')
])
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.constructor.SafeConstructor
import org.mockito.Mockito

Logger logger = Logger.getLogger("")
Jenkins jenkins = Jenkins.getInstance()
Expand All @@ -34,17 +38,39 @@ def descriptor = jenkins.getDescriptorByType(
hudson.tasks.Mailer.DescriptorImpl.class
)
JSONObject json = new JSONObject()
json.put('smtpServer', mailerConfig.SMTP_SERVER)
json.put('replyToAddress', mailerConfig.REPLY_TO_ADDRESS)
json.put('defaultSuffix', mailerConfig.DEFAULT_SUFFIX)
JSONObject auth = new JSONObject()
auth.put('smtpAuthUserName', mailerConfig.SMTP_AUTH_USERNAME)
auth.put('smtpAuthPasswordSecret', mailerConfig.SMTP_AUTH_PASSWORD)
json.put('useSMTPAuth', auth)
json.put('smtpPort', mailerConfig.SMTP_PORT)
json.put('useSsl', mailerConfig.USE_SSL)
json.put('charset', mailerConfig.CHAR_SET)
StaplerRequest stapler = null
json.put('smtpHost', mailerConfig.SMTP_SERVER)
// json.put('adminAddress', mailerConfig.REPLY_TO_ADDRESS) // this is deprecated as of 1.4 but adding it in for testing
// json.put('authentication', true)
// json.put('username', mailerConfig.SMTP_AUTH_USERNAME)
// json.put('password', mailerConfig.SMTP_AUTH_PASSWORD)
// json.put('useSsl', mailerConfig.USE_SSL)
// json.put('useTls', true)
// json.put('smtpPort', mailerConfig.SMTP_PORT)
// json.put('charset', mailerConfig.CHAR_SET)
// json.put('sendTestMailTo', mailerConfig.REPLY_TO_ADDRESS) // dunno what tthis should be

// these are extra??
//json.put('replyToAddress', mailerConfig.REPLY_TO_ADDRESS)
// json.put('address', mailerConfig.REPLY_TO_ADDRESS)
// json.put('defaultSuffix', mailerConfig.DEFAULT_SUFFIX)

// JSONObject auth = new JSONObject()
// auth.put('smtpAuthUserName', mailerConfig.SMTP_AUTH_USERNAME)
// auth.put('smtpAuthPasswordSecret', mailerConfig.SMTP_AUTH_PASSWORD)
// json.put('useSMTPAuth', auth)


logger.info("hey its chris====================")
logger.info(json.toString())
// Changing how we creeate stapler gets us by the first nullpointerexception
StaplerRequest stapler = new RequestImpl(
new Stapler(),
Mockito.mock(HttpServletRequestWrapper.class),
new ArrayList<AncestorImpl>(),
new TokenList("")
)


try {
descriptor.configure(stapler, json)
} catch (JSONException e) {
Expand All @@ -58,4 +84,13 @@ try {
jenkins.doSafeExit(null)
System.exit(1)
}
// catch (NullPointerException e) {
// logger.severe("YO DAWG.zzzzz there was a null point=============")
// logger.severe(e.toString())
// logger.severe(mailerConfig.toString())
// logger.severe(json.toString())
// //logger.severe(auth.toString())
// jenkins.doSafeExit(null)
// System.exit(1)
// }
logger.info('Successfully configured the mailer plugin')