Last active
July 12, 2016 17:05
-
-
Save mkoertgen/c9dcca7a6dbc09e8f80b to your computer and use it in GitHub Desktop.
Install a jenkins build server for .NET projects with boxstarter
This file contains 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
Scripts for jenkins build server automation on windows |
This file contains 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
slave.jar | |
jenkins.war | |
defaults.bat | |
slave-agent.jnlp |
This file contains 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
@echo off | |
setlocal | |
set DIR=%~dp0 | |
set command=%1 | |
set role=%2 | |
rem https://gist.github.com/mkoertgen/c9dcca7a6dbc09e8f80b | |
rem What you need | |
rem 1. jenkins.war | |
rem 2. slave.jar | |
rem 3. credentials: | |
rem - user,pwd (logon for scheduled task) | |
rem - for slave: jnlpUrl, jnlpCredentials=user:apitoken | |
set jenkinsDir=%3 | |
set taskUser=%4 | |
set taskPwd=%5 | |
set jnlpUrl=%6 | |
set jnlpCredentials=%7 | |
set taskName=%~n0 | |
:set_defaults | |
if exist "%DIR%defaults.bat" call "%DIR%defaults.bat" | |
if "%jenkinsDir%"=="" set jenkinsDir=%DIR% | |
if "%jenkinsPort%"=="" set jenkinsPort=80 | |
if "%command%"=="" set command=usage | |
goto %command% | |
:usage | |
echo Run '%taskName%' as scheduled task | |
echo. | |
echo Usage: %~n0 [command] | |
echo. | |
echo Available commands: | |
echo. | |
echo usage Shows this help | |
echo run Run '%taskName%' | |
echo install Install '%taskName%' | |
echo start Start '%taskName%' | |
echo stop Stop '%taskName%' | |
echo status Show status of '%taskName%' | |
echo restart Restart '%taskName%' | |
echo uninstall Uninstall '%taskName%' | |
goto end | |
:install | |
echo Installing '%taskName%' (%role%) ... | |
echo. | |
xcopy /D /H /R /E /I /Y /Q "%DIR%*.*" "%jenkinsDir%\" | |
call :check_error %errorlevel% "Could not copy installation files." || exit /B 1 | |
schtasks /Create /TN %taskName% /RU %taskUser% /RP %taskPwd% /SC onstart /RL HIGHEST /DELAY 0000:30 /TR "%jenkinsDir%\%~n0 run %role%" | |
call :check_error %errorlevel% "Could not install '%taskName%'." || exit /B 1 | |
echo. | |
call :start || exit /B 2 | |
echo. | |
echo Installed '%taskName%'. | |
goto end | |
:uninstall | |
echo Uninstalling '%taskName%' ... | |
echo. | |
call :stop || exit /B 2 | |
schtasks /Delete /TN %taskName% /f | |
call :check_error %errorlevel% "Could not uninstall '%taskName%'." || exit /B 1 | |
rem wait 5 seconds to relieve access problems to logfile | |
ping 127.0.0.1 -n 5 > nul | |
rem rmdir /S /Q "%jenkinsDir%" | |
echo. | |
echo Uninstalled '%taskName%'. | |
goto end | |
:start | |
echo Starting '%taskName%' ... | |
schtasks /Run /I /TN %taskName% | |
call :check_error %errorlevel% "Could not start '%taskName%'." || exit /B 1 | |
echo Started '%taskName%'. | |
goto end | |
:stop | |
schtasks /End /TN %taskName% | |
call :check_error %errorlevel% "Could not stop '%taskName%'." || exit /B 1 | |
taskkill /im java.exe /f /FI "WINDOWTITLE eq Jenkins" >nul 2>&1 | |
echo Stopped '%taskName%'. | |
goto end | |
:status | |
echo Status of '%taskName%' is ... | |
schtasks /Query /TN %taskName% | |
goto end | |
:restart | |
echo Restarting '%taskName%' ... | |
echo. | |
call :stop || exit /B 1 | |
echo. | |
call :start || exit /B 2 | |
echo. | |
echo Restarted '%taskName%'. | |
goto end | |
:run | |
echo Starting 'Jenkins' (%role%) ... | |
echo Please keep this window open (minimized is OK). | |
cd /D "%jenkinsDir%" | |
if "%JENKINS_HOME%"=="" set JENKINS_HOME=%jenkinsDir%\home | |
if not exist "%JENKINS_HOME%" mkdir "%JENKINS_HOME%" 2>nul | |
if "%role%"=="master" ( | |
set jargs=-Xrs -Xmx512m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar jenkins.war --httpPort=%jenkinsPort% | |
) else ( | |
set jargs=-jar slave.jar -jnlpUrl %jnlpUrl% -jnlpCredentials %jnlpCredentials% | |
) | |
start "Jenkins" /B /high /wait java %jargs% > %JENKINS_HOME%\jenkins.log 2>&1 | |
rem exit code 1 is Ok (Ctrl+C) | |
call :check_error %errorlevel% "Could not run 'Jenkins'." || exit /B 1 | |
goto end | |
:end | |
endlocal | |
exit /B 0 | |
:check_error | |
set /a exitCode = %1 | |
set /a okCode = 0 | |
if not "%3"=="" set /a okCode = %3 | |
if %exitCode% equ %okCode% exit /B 0 | |
echo ERROR: %2 (code: %exitCode%) | |
if "%4"=="log" echo ERROR: %2 (code: %exitCode%) >>%logfile% | |
exit /B %exitCode% |
This file contains 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-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -EnableShowProtectedOSFiles -EnableShowFileExtensions -EnableShowFullPathInTitleBar | |
Enable-RemoteDesktop | |
Disable-InternetExplorerESC | |
# for machine | |
#& setx /m HTTP_PROXY http://[proxy] | |
#& setx /m HTTPS_PROXY http://[proxy] | |
#& setx /m NO_PROXY .dns.suffix | |
# for this process | |
#& set HTTP_PROXY=http://[proxy] | |
#& set HTTPS_PROXY=http://[proxy] | |
#& set NO_PROXY=.dns.suffix | |
# jenkins | |
cinst git -params '"/GitAndUnixToolsOnPath /NoAutoCrlf"' -y | |
# & setx /m PATH "%PATH%;C:\Program Files\Git\bin" | |
cinst jdk8 -y | |
# for a Jenkins slave we are done, for a master we need jenkins | |
#cinst jenkins -y | |
# TODO | |
# msbuild14, fxcop14 | |
# cf.: https://gist.github.com/mkoertgen/417e8d3dfbe6ae8bc2f7 | |
# "path\install_fxcop14.bat" | |
cinst netfx-4.5.2-devpack -y | |
# nuget | |
cinst nuget.commandline -y | |
# gitversion | |
cinst gitversion.portable -y | |
# mkdocs | |
cinst plantuml -y | |
cinst python -y | |
pip install mkdocs | |
# cleaver | |
cinst nodejs -y | |
cinst phantomjs -y | |
npm install -g cleaver | |
# sonar | |
# ignore dependency jre8, we already have jdk8 | |
cinst sonar-runner -y -i | |
# powercli | |
# PS4 & management framework (prerequisite, usually needs reboot) | |
cinst powershell -y | |
# boxstarter for deployments targeting Windows machines | |
cinst boxstarter -y | |
# TODO... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use this?
jenkins.ps1
for this machinejenkins.bat install
Be sure to read the comments in the scripts.
After cloning specify your settings in the
defaults.bat
. Here is an example: