Modify Kick_Jenkins.cmd to run build job on current repo and topic branch

This commit is contained in:
Said Fathelbab 2016-07-14 18:07:42 -07:00
Родитель 9062118ec7
Коммит ddfa6ea06e
2 изменённых файлов: 62 добавлений и 11 удалений

2
.gitignore поставляемый
Просмотреть файл

@ -5,3 +5,5 @@
/build_all/windows/nuget.exe
/cmake
/devdoc/~$o_requirements.docm
*.jar

Просмотреть файл

@ -1,6 +1,27 @@
@setlocal
@echo off
set current-path=%~dp0
rem // remove trailing slash
set current-path=%current-path:~0,-1%
set build-root=%current-path%\..
rem // resolve to fully qualified path
for %%i in ("%build-root%") do set build-root=%%~fi
REM check that we have java handy
call :checkExists java
if not %errorlevel%==0 exit /b %errorlevel%
REM check that jenkins-cli.jar is in the repository's tools folder
if not exist %build-root%\tools\jenkins-cli.jar (
echo jenkins-cli does not exist
echo Use the following link to download it into the tools folder of your repository:
echo http://azure-iot-sdks-ci.westus.cloudapp.azure.com:8080/jnlpJars/jenkins-cli.jar
exit /b 1
)
REM find current branch
for /f "usebackq tokens=*" %%i in (`git symbolic-ref -q HEAD`) do set "current_branch_ref=%%i"
if defined current_branch_ref set "current_branch=%current_branch_ref:refs/heads/=%"
@ -11,7 +32,7 @@ if not defined current_branch (
goto :eof
)
REM Don't rewrite history on 'develop' or 'master' branches
REM Must be on a topic branch when running this script
set __exit=1
if not "%current_branch%"=="master" if not "%current_branch%"=="develop" set __exit=0
if %__exit%==1 (
@ -22,23 +43,51 @@ if %__exit%==1 (
REM find tracking branch
for /f "usebackq tokens=*" %%i in (`git rev-parse --symbolic-full-name --abbrev-ref @{u}`) do set "tracking_branch=%%i"
if not defined tracking_branch (
echo Branch ^'%current_branch%^' is not tracking a remote branch! Aborting...
echo Branch ^'%current_branch%^' is not tracking a remote branch! First try ^'git branch -u ^<remote^>/^<branch^>^' to set tracking info. Aborting...
goto :eof
)
for /f "usebackq tokens=*" %%i in (`git log --oneline -1`) do set "head_commit=%%i"
choice /C yn /M "Rewrite HEAD commit (%head_commit%) on branch '%current_branch%', and push to '%tracking_branch%'?"
if not %errorlevel%==1 goto :eof
for /f "usebackq tokens=*" %%i in (`git config branch.%current_branch%.remote`) do set "remote=%%i"
if not defined remote (
REM should never happen...
echo Error: could not isolate remote name for tracking branch ^'%tracking_branch%^'! Aborting...
echo Cannot isolate remote name for tracking branch ^'%tracking_branch%^'! Aborting...
goto :eof
)
for /f "usebackq tokens=*" %%i in (`call echo %%tracking_branch:%remote%/^=%%`) do set "tracking_abbrev=%%i"
REM get the tracking branch name only e.g., origin/topic -> topic
for /f "usebackq tokens=*" %%i in (`call echo %%tracking_branch:%remote%/^=%%`) do set "tracking_name=%%i"
REM find repo url
for /f "usebackq tokens=*" %%i in (`git ls-remote --heads --get-url %remote%`) do set "repo_url=%%i"
if not defined repo_url (
echo Cannot find the remote repository URL! Aborting...
goto :eof
)
echo ****************************************************************
echo commit_id: %current_branch%
echo repo_url: %repo_url%
echo remote: %remote%
echo trackingN: %tracking_name%
echo ****************************************************************
REM kick off the build!
java -jar "%build-root%"\tools\jenkins-cli.jar -s http://azure-iot-sdks-ci.westus.cloudapp.azure.com:8080/ build _anyrepo2M-integrate-into-develop -p COMMIT_ID=%tracking_name% -p AZURE_REPO=%repo_url% -p BRANCH_TO_MERGE_TO=develop -s -v
rem -----------------------------------------------------------------------------
rem -- done
rem -----------------------------------------------------------------------------
goto :eof
rem -----------------------------------------------------------------------------
rem -- helper subroutines
rem -----------------------------------------------------------------------------
:checkExists
where %~1 >nul 2>nul
if not %errorlevel%==0 (
echo "%~1" not found. Please make sure that "%~1" is installed and available in the path.
exit /b %errorlevel%
)
goto :eof
git commit --amend --no-edit
git push -f %remote% %current_branch%:%tracking_abbrev%