Last active
July 6, 2017 01:15
-
-
Save MakotoUwaya/485d03b5980b281d9fd24d8f20348111 to your computer and use it in GitHub Desktop.
Jenkins 設定バックアップ PowerShell版
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 変数定義 | |
| Set-Location .. | |
| $JenkinsHome = (Convert-Path ..) | |
| Set-Location (".\" + $ENV:JOB_NAME) | |
| $HostPcName = $env:COMPUTERNAME.ToLower() | |
| $BackupPath = $env:UserProfile + "\Documents\business-app-jenkins-backup" | |
| $ArchivePath = $HostPcName + "\jenkins-backup" | |
| # ファイルのクリア | |
| Remove-Item -Path ($BackupPath + "\" + $HostPcName) -Recurse -Force | |
| # Jenkins設定ファイルのバックアップ | |
| New-Item -Path ($BackupPath + "\" + $ArchivePath) -ItemType Directory | |
| Copy-Item ($JenkinsHome + "\*.xml") -Destination ($BackupPath + "\" + $ArchivePath) | |
| $DirectoryBackupTargets = @("nodes", "secrets", "users") | |
| foreach ($dir in $DirectoryBackupTargets) { | |
| Copy-Item ($JenkinsHome + "\" + $dir) -Destination ($BackupPath + "\" + $ArchivePath + "\" + $dir) -Recurse | |
| } | |
| $JpiBackupTargets = @("plugins") | |
| foreach ($jpi in $JpiBackupTargets) { | |
| New-Item -Path ($BackupPath + "\" + $ArchivePath + "\" + $jpi) -ItemType Directory | |
| Copy-Item ($JenkinsHome + "\" + $jpi + "\*.jpi") -Destination ($BackupPath + "\" + $ArchivePath + "\" + $jpi) | |
| } | |
| foreach ($job in Get-ChildItem -Path ($JenkinsHome + "\jobs")) { | |
| New-Item -Path ($BackupPath + "\" + $ArchivePath + "\jobs\" + $job.Name) -ItemType Directory | |
| Copy-Item ($JenkinsHome + "\jobs\" + $job.Name + "\*.xml") -Destination ($BackupPath + "\" + $ArchivePath + "\jobs\" + $job.Name) | |
| } | |
| # 変更内容をGitに反映してリモートにプッシュ | |
| Set-Location -Path $BackupPath | |
| git pull | |
| git add $HostPcName | |
| $gitresult = git status | |
| if ($gitresult -match "nothing to commit") { | |
| Write-Output "no changes." | |
| } else { | |
| git commit -m ("backup " + (Get-Date).ToString("yyyy/MM/dd HH:mm:ss")) | |
| git push origin develop | |
| } | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment