source:
Jenkins/Promote@
fae93a40
| Last change on this file since fae93a40 was fae93a40, checked in by , 3 months ago | |
|---|---|
|
|
| File size: 1.6 KB | |
| Line | |
|---|---|
| 1 | #!groovy |
| 2 | |
| 3 | import groovy.transform.Field |
| 4 | |
| 5 | // Globals |
| 6 | @Field def BuildDir = null |
| 7 | @Field def SrcDir = null |
| 8 | @Field def RemoteRepo = '' |
| 9 | @Field def ArchiveUrl = '' |
| 10 | |
| 11 | // Local variables |
| 12 | def err = null |
| 13 | def log_needed = false |
| 14 | |
| 15 | node { |
| 16 | BuildDir = pwd tmp: true |
| 17 | SrcDir = pwd tmp: false |
| 18 | RemoteRepo = 'git@github.com:cforall/cforall.git' |
| 19 | ArchiveUrl = 'https://cforall.uwaterloo.ca/jenkins/job/Cforall_Distribute_Ref/lastSuccessfulBuild/artifact/*zip*/archive.zip' |
| 20 | currentBuild.result = "SUCCESS" |
| 21 | |
| 22 | // Wrap build to add timestamp to command line |
| 23 | wrap([$class: 'TimestamperBuildWrapper']) { |
| 24 | PrepRepo(); |
| 25 | def name = GetArchive(); |
| 26 | PushRepo(name); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | def GetTarName() { |
| 31 | def files = findFiles(glob: 'archive/cfa-cc-*.tar.gz') |
| 32 | echo "found: ${files[0].name}" |
| 33 | return files[0].name - '.tar.gz'; |
| 34 | } |
| 35 | |
| 36 | def PrepRepo() { |
| 37 | stage('Clone') { // for display purposes |
| 38 | dir (BuildDir) { |
| 39 | sh 'rm -rf *' |
| 40 | sshagent (credentials: ['git_key_aug2025']) { |
| 41 | sh "git clone --bare ${RemoteRepo} repo" |
| 42 | } |
| 43 | dir ('repo') { |
| 44 | sh "mkdir .git" |
| 45 | sh "mv * .git" |
| 46 | sh "git init" |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | def GetArchive() { |
| 53 | def tarball |
| 54 | stage('Unzip') { // for display purposes |
| 55 | dir (BuildDir) { |
| 56 | sh "wget -q ${ArchiveUrl}" |
| 57 | sh "unzip archive.zip" |
| 58 | tarball = GetTarName(); |
| 59 | sh "tar -xzf archive/${tarball}.tar.gz" |
| 60 | sh "mv ${tarball}/* repo/." |
| 61 | } |
| 62 | } |
| 63 | return tarball |
| 64 | } |
| 65 | |
| 66 | def PushRepo(name) { |
| 67 | stage('Push') { // for display purposes |
| 68 | dir ("${BuildDir}/repo") { |
| 69 | sh "git add -A" |
| 70 | sh "git status" |
| 71 | sh "git diff-index --quiet HEAD || git commit -m 'Push from build machine: ${name}'" |
| 72 | sshagent (credentials: ['git_key_aug2025']) { |
| 73 | sh "git push origin master" |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } |
Note:
See TracBrowser
for help on using the repository browser.