Skip to content

Instantly share code, notes, and snippets.

@phxswjjj
Last active January 15, 2023 22:16
Show Gist options
  • Save phxswjjj/281bf9beddb7381fbd627385d503fd03 to your computer and use it in GitHub Desktop.
Save phxswjjj/281bf9beddb7381fbd627385d503fd03 to your computer and use it in GitHub Desktop.
win app clickonce deploy by gitlab runner
stages:
- restore
- deploy
before_script:
- echo before_script
restore_job:
stage: restore
only:
- master
tags:
- docker
script:
- echo restore_job
deploy_job:
stage: deploy
only:
- master
tags:
- docker
when: manual
script:
- echo deploy_job
- curl http://fail.local
- touch success.lock
after_script:
- echo deploy_job after_script
- >
if [ -f success.lock ]; then
echo 'This will only run on success'
else
echo 'This will only run when job failed or is cancelled'
fi
- echo completed
deploy2_job:
stage: deploy
only:
- master
tags:
- docker
when: manual
script:
- echo deploy_job
- curl http://172.21.76.197
- touch success.lock
after_script:
- echo deploy_job after_script
- >
if [ -f success.lock ]; then
echo 'This will only run on success'
else
echo 'This will only run when job failed or is cancelled'
fi
- echo completed
variables:
MySolution: WebApp.sln
MyProject: WebApp\WebApp.csproj
MyVsPath: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
CacheKey: Default
MyProjectToken: uVxLM6x1xgfGoh4ByoT9
MyGitlabDns: gitlab.local
MyProjectPath: root/WebApp
MyTagPrefix: DEPLOY/PROD
cache:
key: '%CacheKey%'
paths:
- 'packages/'
stages:
- restore
- deploy
before_script:
- chcp 65001
- set MyMSBuild=%MyVsPath%\MSBuild\Current\Bin\MSBuild.exe
- set VSToolCmd=%MyVsPath%\Common7\Tools\VsDevCmd.bat
- call "%VSToolCmd%"
restore_job:
stage: restore
only:
- master
tags:
- windows
script:
- nuget restore %MySolution%
deploy_job:
stage: deploy
only:
- master
when: manual
tags:
- windows
script:
- '"%MyMSBuild%" "%MyProject%" /p:DeployOnBuild=true;PublishProfile=DeployProfile.pubxml;Password=%DeployPWD%'
- echo %date%, %time%
- set /A dy=%date:~5,2%*1
- set /A dd=10000 + %date:~8,2%*100 + %date:~11,2%*1
- set /A dt=10000 + %time:~0,2%*100 + %time:~3,2%*1
# DEPLOY/PROD_220330_1148
- set MyTag=%MyTagPrefix%_%dy%%dd:~1%_%dt:~1%
- echo %MyTag%
- git config user.email "deploy@%MyGitlabDns%"
- git config user.name "deploy"
- git tag -a "%MyTag%" -m "auto deploy"
- git push http://root:%MyProjectToken%@%MyGitlabDns%/%MyProjectPath%.git "%MyTag%"
variables:
MySolution: WindowsFormsApp2.sln
MyProject: WindowsFormsApp2\WindowsFormsApp2.csproj
MyMSBuild: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe
VSToolCmd: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat
CacheKey: Default
MyDeployDir: \\win22.local\deploy$$\WinApp
MyProjectToken: uVxLM6x1xgfGoh4ByoT9
MyTokenOwner: root
MyGitlabDns: gitlab.local
MyProjectPath: root/test
NETWORK_USER: '%DeployUser%'
NETWORK_PASS: '%DeployPWD%'
cache:
key: '%CacheKey%'
paths:
- 'packages/'
stages:
- restore
- build
- deploy
before_script:
- chcp 65001
- call "%VSToolCmd%"
- if not exist %MyDeployDir% net use %MyDeployDir% /USER:%NETWORK_USER% %NETWORK_PASS%
restore_job:
stage: restore
only:
- master
- develop
tags:
- windows
script:
- nuget restore "%MySolution%"
build_prod_job:
stage: build
only:
- master
tags:
- windows
script:
- '"%MyMSBuild%" "%MyProject%" /t:build /p:Configuration=Release'
build_test_job:
stage: build
only:
- develop
tags:
- windows
script:
- '"%MyMSBuild%" "%MyProject%" /t:build /p:Configuration=Debug'
deploy_prod_job:
stage: deploy
only:
- master
when: manual
tags:
- windows
script:
- echo %date%, %time%
# 週X 2008/08/08, 8:08:08.08
- set /a dyy=%date:~3,2%-19
- set /a dy=%date:~3,4%-2000
- set /a dd=(1%date:~8,2%00 + 100%date:~11,2%) %% 10000
- set /a dt=(%time:~0,2%00 + 100%time:~3,2%) %% 10000
# 1.8.808.808
- set MyVersion=%dyy%.%dy%.%dd%.%dt%
- echo Version=%MyVersion%
- '"%MyMSBuild%" %MySolution% /t:publish /p:PublishDir="%MyDeployDir%\PROD\\";ApplicationVersion=%MyVersion%;Configuration=Release'
- echo tag job
# v1.8.808.808
- set MyTag=v%MyVersion%
- echo %MyTag%
- git config user.email "deploy@%MyGitlabDns%"
- git config user.name "deploy"
- git tag -a "%MyTag%" -m "auto deploy"
- git push http://%MyTokenOwner%:%MyProjectToken%@%MyGitlabDns%/%MyProjectPath%.git "%MyTag%"
deploy_test_job:
stage: deploy
only:
- develop
tags:
- windows
script:
- echo %date%, %time%
# 週X 2008/08/08, 8:08:08.08
- set /a dyy=%date:~3,2%-19
- set /a dy=%date:~3,4%-2000
- set /a dd=(1%date:~8,2%00 + 100%date:~11,2%) %% 10000
- set /a dt=(%time:~0,2%00 + 100%time:~3,2%) %% 10000
# 1.8.808.808
- set MyVersion=%dyy%.%dy%.%dd%.%dt%
- echo Version=%MyVersion%
- '"%MyMSBuild%" %MySolution% /t:publish /p:PublishDir="%MyDeployDir%\TEST\\";ApplicationVersion=%MyVersion%;Configuration=Debug'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment