stage('Copy to NAS with Login') {
steps {
withCredentials([usernamePassword(credentialsId: 'nas-credentials', usernameVariable: 'NAS_USER', passwordVariable: 'NAS_PASS')]) {
bat '''
chcp 65001
set "NAS_PATH=\\\\NAS01\\coverage-reports"
net use %NAS_PATH% /user:%NAS_USER% %NAS_PASS%
set "src=%WORKSPACE%\\build\\reports\\jacoco"
set "dst=%NAS_PATH%\\%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%"
mkdir "%dst%"
robocopy "%src%" "%dst%" /E
'''
}
}
}
自分用
stage('Zip and Upload Coverage to NAS') {
steps {
withCredentials([usernamePassword(credentialsId: 'nas-credentials', usernameVariable: 'NAS_USER', passwordVariable: 'NAS_PASS')]) {
bat '''
chcp 65001
rem ====== 日付フォルダ名を作成 ======
for /f %%i in ('powershell -Command "Get-Date -Format yyyyMMdd"') do set DATE_DIR=%%i
rem ====== ZIPファイル作成 ======
powershell -Command "Compress-Archive -Path build\\reports\\jacoco\\* -DestinationPath build\\reports\\jacoco\\jacoco_%DATE_DIR%.zip -Force"
rem ====== NASへ接続 ======
set "NAS_PATH=\\\\NAS01\\coverage-reports"
net use %NAS_PATH% /user:%NAS_USER% %NAS_PASS%
rem ====== アップロード ======
copy build\\reports\\jacoco\\jacoco_%DATE_DIR%.zip %NAS_PATH%\\jacoco_%DATE_DIR%.zip
rem ====== 接続解除(必要に応じて) ======
net use %NAS_PATH% /delete /yes
'''
}
}
}