Project

General

Profile

1
def myFile= new File("/var/lib/jenkins/jobs/dnet-dsl-job/workspace/configuration.xml")
2
def parser=new XmlSlurper().parseText(myFile.text);
3
print "I'm Here and it works"
4
def allModule=parser.module.each {
5
        def projectName= it.name as String
6
        def sourceCodeType=it.source.@type
7
        def versionCode = it.source.@version
8
        def URLSource=it.source as String        
9
        def mvnGoal= it.goal as String
10
        def hasSonar= it.sonar as String
11
        def mail = it.mail as String
12
        def repositoryId = it.deploy.RepositoryId as String
13
        def repositoryURL = it.deploy.RepositoryURL as String
14
        job(type: Maven) {
15
            if (versionCode == '4')
16
                {
17
                    name 'DSL4_'+projectName    
18
                    using ("dnet4-svn-template")
19
                }
20
                else{
21
                    name 'DSL_'+projectName
22
                    using ("dnet-svn-template")
23
                }
24
                
25
                triggers 
26
                {
27
                    scm('H/10 * * * *')
28
                }               
29
            configure { 
30
                        project -> 
31
                        def goalModule=project / goals
32
                        goalModule.value=mvnGoal
33
                        def scm= project / scm
34
                        def remoteNode= scm.locations.'hudson.scm.SubversionSCM_-ModuleLocation'[0].remote[0]                        
35
                        remoteNode.value=URLSource 
36
                        if (mail){
37
                            def publishersNode = project /publishers
38
                            def repo_publisher_node= publishersNode.appendNode('hudson.maven.RedeployPublisher')
39
                            def repoid_node =repo_publisher_node.appendNode('id')
40
                            repoid_node.value = repositoryId
41
                            def repourl_node =repo_publisher_node.appendNode('url')
42
                            repourl_node.value = repositoryURL
43
                            repo_publisher_node.appendNode('uniqueVersion').value='true'
44
                            repo_publisher_node.appendNode('evenIfUnstable').value='true'
45
                            def m1 = publishersNode.appendNode('hudson.plugins.emailext.ExtendedEmailPublisher')
46
                            m1.@plugin= "email-ext@2.36"
47
                            def rec1 = m1.appendNode('recipientList')
48
                            rec1.value= mail
49
                            def ct= m1.appendNode('configuredTriggers')
50
                            def TriggerNode = ct.appendNode('hudson.plugins.emailext.plugins.trigger.FailureTrigger')
51
                            def emailNode = TriggerNode.appendNode('email')
52
                            emailNode  << {
53
                                recipientList ()
54
                                subject ('Jenkins Job Problem on $PROJECT_NAME - Build # $BUILD_NUMBER')
55
                                body ('$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS: Check console output at $BUILD_URL to view the results.')
56
                                sendToDevelopers ('true')
57
                                sendToRequester ('true')
58
                                includeCulprits('true')
59
                                sendToRecipientList('true')
60
                                attachmentsPattern('')
61
                                attachBuildLog('true')
62
                                compressBuildLog('false')
63
                                replyTo (mail)
64
                                contentType('text/html')
65
                            }
66
                            TriggerNode.appendNode('attachBuildLog').value='true'
67
                            TriggerNode.appendNode('defaultSubject').value='Jenkins Job Problem on $PROJECT_NAME - Build # $BUILD_NUMBER'
68
                            TriggerNode.appendNode('defaultContent').value='$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS: Check console output at $BUILD_URL to view the results.'
69
                            TriggerNode.appendNode('contentType').value='text/html'
70

    
71

    
72
                        }                       
73
                        if (hasSonar.equals("YES")) {
74
                            def pubblish=(project /publishers)
75
                            ppNode=pubblish.appendNode('hudson.plugins.sonar.SonarPublisher')
76
                            ppNode.@plugin="sonar@2.1"
77
                            ppNode.appendNode('jdk').value= '(Inherit From Job)'
78
                            }
79
                    }
80
        }
81
}
(2-2/2)