|
| 1 | +# Support QA image copy dynamically |
| 2 | + |
| 3 | +This section provides an example that images are automatically copied from a known location where nightly builds are done to a given location that is needed by the sanity that is being executed by XPRESSO on Jenkins. There are many ways to achieve this on Jenkins, users can use the below mechanism template to customize their own solutions. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## Step 1: create a project with parameters |
| 8 | +* create a free style project (similar way if user use Pipline or Build Flow project) |
| 9 | +* configure 3 'String' parameters: |
| 10 | + - IMAGE_PATH (source image nightly build folder, for example Cisco automount locaiton) |
| 11 | + - IMAGE_NAME (image name, support regx pattern) |
| 12 | + - TARGET (image copied destination, can be another Cisco automount location or typical local Jenkins workspace) |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +## Step 2 schedule the run: |
| 17 | +Configure the job to run each day at 2 AM. User can set his own schedule by using cron syntax. |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +## Step 3 add a build step to copy the image: |
| 23 | +There are many ways to copy image files from one location to another in Jenkins, most need special setup or some third party plugins, for example 'file operations': https://wiki.jenkins.io/display/JENKINS/File+Operations+Plugin |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +In case the user has Cisco EngIT managed Jenkins, which installing plugins and configuring system settings can be limitations. Here we use native Jenkins shell command to achieve the requirements. Add build step: Execute shell |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +Check the comments in the following code, and customize the commands as users' requirements. |
| 32 | + |
| 33 | + # find the latest image folder created from the nightly builds |
| 34 | + LATEST_IMAGE_FOLDER=$(ls -td $IMAGE_PATH/*/ | head -1) |
| 35 | + |
| 36 | + # build the latest image source path |
| 37 | + LEN=${#LATEST_IMAGE_FOLDER} |
| 38 | + LATEST_IMAGE_FOLDER=${LATEST_IMAGE_FOLDER::LEN-1} |
| 39 | + FINAL_IMAGE_PATH=$LATEST_IMAGE_FOLDER/$IMAGE_NAME |
| 40 | + |
| 41 | + # make sure there is a target image we want to copy and test, sometimes if build failed, empty folder created |
| 42 | + if ls $FINAL_IMAGE_PATH 1> /dev/null 2>&1; then |
| 43 | + echo "files do exist" |
| 44 | + # copy the image from source to destination defined in $TARGET, rename it to a unique known to the next build step |
| 45 | + # if want to copy the image to local Jenkins. instead of $TARGET, use $WORKSPACE |
| 46 | + cp $FINAL_IMAGE_PATH $TARGET/cat9k_latest_$BUILD_ID.SSA.bin |
| 47 | + else |
| 48 | + # no image found, exit the curent build |
| 49 | + echo "Image directory is empty! Aborting the build, and see you tomorrow :)" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + |
| 53 | +## Step 4 trigger the xpresso build using the image: |
| 54 | +After the previous step, the image file should be copied to the location the executor Jenkins be able to access. |
| 55 | + |
| 56 | +Assume the job have already properly registered on the Xpresso already. |
| 57 | + |
| 58 | +Add build step: Execute Xpresso Job. Specify the image info with Json format in the "clean info" section. |
| 59 | + |
| 60 | + |
0 commit comments