Merge pull request #37 from iamshital/master

Added support to pass parameters using parameters file as well as command line
This commit is contained in:
Shital Savekar 2018-05-31 11:31:06 -07:00 коммит произвёл GitHub
Родитель 9420a5bf58 349977db8e
Коммит 85ac33bd02
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 158 добавлений и 81 удалений

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

@ -685,7 +685,7 @@ Function CreateResourceGroupDeployment([string]$RGName, $location, $setupType, $
{
$FailCounter = 0
$retValue = "False"
$ResourceGroupDeploymentName = $RGName + "-deployment"
$ResourceGroupDeploymentName = "eosg" + (Get-Date).Ticks
While(($retValue -eq $false) -and ($FailCounter -lt 1))
{
try
@ -2638,7 +2638,7 @@ Function CreateRGDeploymentWithTempParameters([string]$RGName, $TemplateFile, $T
{
$FailCounter = 0
$retValue = "False"
$ResourceGroupDeploymentName = $RGName + "-deployment"
$ResourceGroupDeploymentName = "eosg" + (Get-Date).Ticks
While(($retValue -eq $false) -and ($FailCounter -lt 1))
{
try

Двоичные данные
Tools/jq Normal file

Двоичный файл не отображается.

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

@ -10,70 +10,39 @@
#!/bin/bash
#Required
JenkinsUser="microsoft"
#####################################################################################################
#How to use:
#Required
UpstreamBuildNumber="unique-string"
# Method 1: You can pass all the parameters from a parameters file.
#./LaunchTestPipelineRemotely.sh -ParametersFile <Path to parameters file>
#Required any one of the following
ImageSource=""
CustomVHD=""
CustomVHDURL=""
# Method 2: You can also pass all the perameters to commandline.
#./LaunchTestPipelineRemotely.sh -JenkinsUser "assigned username" -UpstreamBuildNumber <UniqueBuildID> ... etc.
if [ - $ImageSource ];
echo "Missing required parameter - ImageSource"
fi
######################################################################################################
if [ - $CustomVHD ];
echo "Missing required parameter - CustomVHD"
fi
while echo $1 | grep ^- > /dev/null; do
eval $( echo $1 | sed 's/-//g' | tr -d '\012')=$2
shift
shift
done
if [ - $CustomVHDURL ];
echo "Missing required parameter - CustomVHDURL"
fi
#Required
Kernel="default"
#Required any of the following if Kernel=custom
CustomKernelFile=""
CustomKernelURL=""
#Required
GitUrlForAutomation="https://github.com/LIS/LISAv2.git"
#Required
GitBranchForAutomation="master"
#Required at least one test selection choise from following.
#TestByTestname="Azure>>VERIFY-DEPLOYMENT-PROVISION>>eastus2,Azure>>VERIFY-DEPLOYMENT-PROVISION>>eastus"
TestByTestname=""
TestByCategorisedTestname=""
TestByCategory=""
TestByTag=""
#Required
Email=""
#Optional
LinuxUsername=""
LinuxPassword=""
#Required to access Jenkins.
ApiToken=""
#Required to upload Files to jenkins server using FTP
FtpUsername=""
FtpPassword=""
#Required
#Define static variables
JenkinsURL="penguinator.westus2.cloudapp.azure.com"
#Required
#TestPipeline="/job/Microsoft-Test-Execution-Pipeline"
TestPipeline=""
#Verify the parameters file and import parameters.
if [[ ! -z $ParametersFile ]];
then
echo "Parameters File: $ParametersFile"
if [[ -f $ParametersFile ]];
then
echo "Importing parameters..."
source $ParametersFile
else
echo "Unable to locate $ParametersFile. Exiting with 1"
exit 1
fi
fi
ExitCode=0
@ -87,8 +56,8 @@ then
fi
if [[ $UpstreamBuildNumber == "" ]] || [[ -z $UpstreamBuildNumber ]];
then
echo "UpstreamBuildNumber parameter is required"
ExitCode=$(( ExitCode + 1 ))
UpstreamBuildNumber=$(cat /dev/urandom | tr -dc '0-9' | fold -w 10 | head -1)
echo "UpstreamBuildNumber was not given. Using random build ID: ${UpstreamBuildNumber}"
fi
if ([[ $ImageSource == "" ]] || [[ -z $ImageSource ]]) && ([[ $CustomVHD == "" ]] || [[ -z $CustomVHD ]]) && ([[ $CustomVHDURL == "" ]] || [[ -z $CustomVHDURL ]]);
then
@ -98,15 +67,18 @@ else
if ([[ ! $ImageSource == "" ]] || [[ ! -z $ImageSource ]]);
then
URLEncodedImageSource=${ImageSource// /%20}
echo "ImageSource '${ImageSource}' encoded to '${URLEncodedImageSource}'"
#echo "ImageSource '${ImageSource}' encoded to '${URLEncodedImageSource}'"
fi
if ([[ -f $CustomVHD ]]);
if ([[ ! $CustomVHD == "" ]] || [[ ! -z $CustomVHD ]]);
then
VHDName=$(basename $CustomVHD)
EncodedVHDName="${UpstreamBuildNumber}-${VHDName}"
echo "CustomVHD '${VHDName}' encoded to '${EncodedVHDName}'"
else
echo "CustomVHD '${CustomVHD}' does not exists. Please verify path."
if ([[ -f $CustomVHD ]]);
then
VHDName=$(basename $CustomVHD)
EncodedVHDName="${UpstreamBuildNumber}-${VHDName}"
#echo "CustomVHD '${VHDName}' encoded to '${EncodedVHDName}'"
else
echo "CustomVHD '${CustomVHD}' does not exists. Please verify path."
fi
fi
fi
@ -140,22 +112,22 @@ else
if [[ ! $TestByTestname == "" ]] || [[ ! -z $TestByTestname ]];
then
EncodedTestByTestname=${TestByTestname//>>/%3E%3E}
echo "TestByTestname '${TestByTestname}' encoded to '${EncodedTestByTestname}'"
#echo "TestByTestname '${TestByTestname}' encoded to '${EncodedTestByTestname}'"
fi
if [[ ! $TestByCategorisedTestname == "" ]] || [[ ! -z $TestByCategorisedTestname ]];
then
EncodedTestByCategorisedTestname=${TestByCategorisedTestname//>>/%3E%3E}
echo "TestByCategorisedTestname '${TestByCategorisedTestname}' encoded to '${EncodedTestByCategorisedTestname}'"
#echo "TestByCategorisedTestname '${TestByCategorisedTestname}' encoded to '${EncodedTestByCategorisedTestname}'"
fi
if [[ ! $TestByCategory == "" ]] || [[ ! -z $TestByCategory ]];
then
EncodedTestByCategory=${TestByCategory//>>/%3E%3E}
echo "TestByCategory '${TestByCategory}' encoded to '${EncodedTestEncodedTestByCategoryByTestname}'"
#echo "TestByCategory '${TestByCategory}' encoded to '${EncodedTestEncodedTestByCategoryByTestname}'"
fi
if [[ ! $TestByTag == "" ]] || [[ ! -z $TestByTag ]];
then
EncodedTestByTag=${TestByTag//>>/%3E%3E}
echo "TestByTag '${TestByTag}' encoded to '${EncodedTestByTag}'"
#echo "TestByTag '${TestByTag}' encoded to '${EncodedTestByTag}'"
fi
fi
if [[ $Email == "" ]] || [[ -z $Email ]];
@ -164,7 +136,7 @@ then
ExitCode=$(( ExitCode + 1 ))
else
EncodedEmail=${Email//@/%40}
echo "Email '${Email}' encoded to '${EncodedEmail}'"
#echo "Email '${Email}' encoded to '${EncodedEmail}'"
fi
if [[ $ExitCode == 0 ]];
then
@ -178,7 +150,7 @@ fi
#################################################
#Generate the Link
RemoteTriggerURL="https://${JenkinsUser}:${ApiToken}@${JenkinsURL}${TestPipeline}/buildWithParameters?token=1234567890&JenkinsUser=${JenkinsUser}&UpstreamBuildNumber=${UpstreamBuildNumber}"
RemoteTriggerURL="https://${JenkinsUser}:${ApiToken}@${JenkinsURL}/job/${TestPipeline}/buildWithParameters?token=1234567890&JenkinsUser=${JenkinsUser}&UpstreamBuildNumber=${UpstreamBuildNumber}"
#Add image source.
if ([[ ! $URLEncodedImageSource == "" ]] || [[ ! -z $URLEncodedImageSource ]]);
@ -187,7 +159,7 @@ then
elif ([[ ! $CustomVHD == "" ]] || [[ ! -z $CustomVHD ]]);
then
echo "Uploading ${CustomVHD} with name ${EncodedVHDName}..."
curl -v -T $CustomVHD ftp://${JenkinsURL} --user ${FtpUsername}:${FtpPassword} -Q "-RNFR ${VHDName}" -Q "-RNTO ${EncodedVHDName}"
curl -T $CustomVHD ftp://${JenkinsURL} --user ${FtpUsername}:${FtpPassword} -Q "-RNFR ${VHDName}" -Q "-RNTO ${EncodedVHDName}"
RemoteTriggerURL="${RemoteTriggerURL}&CustomVHD=${VHDName}"
elif ([[ ! $CustomVHDURL == "" ]] || [[ ! -z $CustomVHDURL ]]);
then
@ -216,15 +188,48 @@ then
fi
#Add email
RemoteTriggerURL="${RemoteTriggerURL}&Email=${EncodedEmail}"
RemoteQueryURL="https://${JenkinsUser}:${ApiToken}@${JenkinsURL}${TestPipeline}/lastBuild/api/xml"
echo ${RemoteTriggerURL}
RemoteQueryURL="https://${JenkinsUser}:${ApiToken}@${JenkinsURL}/job/${TestPipeline}/lastBuild/api/xml"
#echo ${RemoteTriggerURL}
echo "Triggering job..."
curl -v -X POST ${RemoteTriggerURL}
curl --silent -X POST ${RemoteTriggerURL}
if [[ "$?" == "0" ]];
then
xmlResponse=$(curl -v -X GET "${RemoteQueryURL}")
echo $xmlResponse | tr ">" "\n" | grep penguinator | tr "<" "\n" | head -1
echo "Job triggered successfully."
if [[ ! -f ./jq ]];
then
echo "Downloading json parser"
curl --silent -O https://raw.githubusercontent.com/LIS/LISAv2/master/Tools/jq
chmod +x jq
fi
BuildNumber=$(curl --silent -X GET "https://${JenkinsUser}:${ApiToken}@${JenkinsURL}/job/${TestPipeline}/lastBuild/api/json" | ./jq '.id' | sed 's/"//g')
BuildURL=$(curl --silent -X GET "https://${JenkinsUser}:${ApiToken}@${JenkinsURL}/job/${TestPipeline}/${BuildNumber}/api/json" | ./jq '.url' | sed 's/"//g')
BuildState=$(curl --silent -X GET "https://${JenkinsUser}:${ApiToken}@${JenkinsURL}/job/${TestPipeline}/${BuildNumber}/api/json" | ./jq '.building' | sed 's/"//g')
BuildResult=$(curl --silent -X GET "https://${JenkinsUser}:${ApiToken}@${JenkinsURL}/job/${TestPipeline}/${BuildNumber}/api/json" | ./jq '.result' | sed 's/"//g')
BlueOceanURL="https://${JenkinsURL}/blue/organizations/jenkins/${TestPipeline}/detail/${TestPipeline}/${BuildNumber}/pipeline"
echo "BuildURL (Classic) : ${BuildURL}"
echo "BuildURL (BlueOcean) : ${BlueOceanURL}"
if [[ $WaitForResult == "yes" ]];
then
while [[ "$BuildState" == "true" ]]
do
BuildState=$(curl --silent -X GET "https://${JenkinsUser}:${ApiToken}@${JenkinsURL}/job/${TestPipeline}/${BuildNumber}/api/json" | ./jq '.building' | sed 's/"//g')
echo "Current state : Running."
sleep 5
done
BuildResult=$(curl --silent -X GET "https://${JenkinsUser}:${ApiToken}@${JenkinsURL}/job/${TestPipeline}/${BuildNumber}/api/json" | ./jq '.result' | sed 's/"//g')
if [[ "$BuildResult" == "SUCCESS" ]];
then
echo "Current State : Completed."
echo "Result: SUCCESS."
exit 0
else
echo "Result: ${BuildResult}"
exit 1
fi
else
exit 0
fi
else
echo "Failed to trigger job."
fi
exit 1
fi

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

@ -0,0 +1,72 @@
#!/bin/bash
##################################################
#Paramerers file for LaunchTestPipelineRemotely.sh
##################################################
#Required (Your jenkins username)
#This will be used to login jenkins in conjuction with ApiToken
JenkinsUser=""
#Required (You can generate your access token in the jenkins.)
ApiToken=""
#Required only if you are uploading files from your local machine to Jenkins. These credentials are different from Jenkins username/password.
FtpUsername=""
FtpPassword=""
#Required (Image / VHD under test)
#Provide ONLY ONE of the following.
ImageSource=""
#Example ImageSource="Publisher Offer Sku Version"
CustomVHD=""
#Example CustomVHD="/path/to/local/vhd/vhdx/vhd.xz file"
CustomVHDURL=""
#Example CustomVHDURL="http://downloadable/link/to/your/file.vhd/vhdx/vhd.xz"
#Required (This kernel be installed before starting test)
Kernel=""
#Example Kernel="default/custom/linuxnext"
#Required ONLY IF you set Kernel=custom
CustomKernelFile=""
#Example CustomKernelFile="/path/to/local/kernel/file.rpm/file.deb"
CustomKernelURL=""
#Example CustomKernelURL="http://downloadable/link/to/your/kernel.rpm/kernel.deb"
#Required (Source code for tests)
GitUrlForAutomation="https://github.com/LIS/LISAv2.git"
#Required
GitBranchForAutomation="master"
#Required AT LEAST ONE test selection choise from following.
#Multiple tests can be submitted using comma separated values
TestByTestname=""
#Example TestByTestname="Azure>>VERIFY-DEPLOYMENT-PROVISION>>eastasia,Azure>>VERIFY-HOSTNAME>>westeurope"
TestByCategorisedTestname=""
#Example TestByCategorisedTestname="Azure>>Smoke>>default>>VERIFY-DEPLOYMENT-PROVISION>>northeurope,Azure>>Functional>>SRIOV>>VERIFY-SRIOV-LSPCI>>southcentralus"
TestByCategory=""
#Example TestByCategory="Azure>>Functional>>SRIOV>>eastus,Azure>>Community>>LTP>>westeurope"
TestByTag=""
#Example TestByTag="Azure>>boot>>northcentralus,Azure>>wala>>westeurope,Azure>>gpu>>eastus"
#Required (Email will be sent to these email addresses. Comma separated email IDs are accepted.
Email=""
#Required (These credential be used to create your test VMs. In case of debugging, you can use this to login to test VM.)
LinuxUsername=""
LinuxPassword=""
#Required (Your pipeline name)
TestPipeline=""
#Example TestPipeline="<PatnerName>-Test-Execution-Pipeline"