-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfileCD
More file actions
70 lines (58 loc) · 2.46 KB
/
Copy pathJenkinsfileCD
File metadata and controls
70 lines (58 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
node {
try {
def branch="Dev" // nome del branch, Dev
def currentTag="0.0" // versione di default
def destFolder = "$JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_NUMBER/archive"
stage('Preparation') { // for display purposes
final scmVars = checkout(scm)
echo "scmVars: ${scmVars}"
echo "scmVars.GIT_COMMIT: ${scmVars.GIT_COMMIT}"
echo "scmVars.GIT_PREVIOUS_SUCCESSFUL_COMMIT: ${scmVars.GIT_PREVIOUS_SUCCESSFUL_COMMIT}"
echo "scmVars.GIT_BRANCH: ${scmVars.GIT_BRANCH}"
// Get some code from a GitHub repository
git branch: branch, credentialsId: 'Jenkins_Gitlab', url: 'http://fsg-tor1-92.altran.it/sw-hub/isp/timesheet.git'
currentTag = powershell(returnStdout: true, script: '''
$tag = git tag --sort=version:refname
$tag[-1]
''').trim()
echo currentTag
echo env.BUILD_TAG
}
stage('CreatingScript'){
echo "Generazione script"
def powershellWrite
powershellWrite = powershell (returnStdout: true, script: '''
$tags = git tag --sort=version:refname
$files = git diff --name-only --diff-filter=d $tags[-2] $tags[-1] timesheet.DB/*.sql
if ($files) {
$currentTag = $tags[-1]
Get-Content -Encoding UTF8 -LiteralPath $files | Set-Content -Encoding UTF8 timesheet.Deploy/DiffScript$currentTag.sql
}else{
Write-Host "nessuna differenza SQL trovata."
}
''')
echo powershellWrite
echo "Script generato"
def fileName = "DiffScript${currentTag}.sql"
echo "sposta file DiffScript.sql in \"${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_NUMBER}/archive/${fileName}\""
bat "md \"${destFolder}\" 2> nul"
bat """
git add -A
git commit -m "DiffScript$currentTag"
git push origin Dev
cd timesheet.Deploy
IF EXIST \"${fileName}\" xcopy \"${fileName}\" \"${destFolder}\"
"""
}
notify("SUCCESSFUL")
} catch(e) {
notify("ERROR")
throw e
}
}
def notify(String buildStatus) {
def mailRecipients = "davide.borghi@altran.it,antonella.touscoz@altran.it"
emailext body: '''<a href="\\\\fsg-tor1-63\\c$\\inetpub\\Applicazioni\\WebAppTest\\CapitalizzazioneISP">Link da cui scaricare il Compilato</a> ${SCRIPT, template="groovy_html.template"}''',
subject: "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
to: "${mailRecipients}"
}