| #!/bin/bash # # Kluge to fix the Extended Choice Parameter. # # ECP's "text box" mode, for whatever reason, was hardcoded to use a # 200-pixel-wide entry box. Using absolute values in HTML rendering # sizes is almost always wrong; in this case it means the box will # be about 30 characters wide – painfully small if the parameter # value is intended to be a path. # # Luckily, this can be fixed by changing one text file inside the # plugin's jar, replacing that "width:200px" with "width:100%". # This value will use as much space as the parent rendering element # is willing to give it. # # Caveat: Pasting this into Jira may have glitched some line breaks... # # Debug trace, if desired #set -xv######################################################################function restart_server { if [ -z $USER ]; then USER=${jenkinsUser} fi if [ -z $PASSWORD ]; then PASSWORD=${jenkinsApiToken} fi if [ -z $USER -o -z $PASSWORD ]; then echo "User and/or password not provided. Please restart Jenkins manually to pick up modified jarfile." {{ else }} CRUMB=`curl -s -u ${USER}:${PASSWORD} "${JENKINS_URL}/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)"` if [[ ${CRUMB} != "Jenkins-Crumb:"* ]]; then echo "Crumb not successfully retrieved; continuing without" CRUMB="" else CRUMB="-H $CRUMB" fi curl -s -X POST -u $USER:$PASSWORD $CRUMB ${JENKINS_URL}/safeRestart if [ $? -eq 0 ]; then echo "Restart requested. There will be a delay for quiescance before restart occurs." else echo "User and password not accepted. Please restart Jenkins manually to pick up modified jarfile." fi fi }###################################################################### # Default assumption: success {{rc=0 }} # Files to be patched: Jarfile, and path within it ecpJarfile=$JENKINS_HOME/plugins/extended-choice-parameter/WEB-INF/lib/extended-choice-parameter.jar textBox="com/cwctravel/hudson/plugins/extended_choice_parameter/ExtendedChoiceParameterDefinition/textboxContent.jelly" # Get a scratch space tmpdir=$(mktemp -d) cd $tmpdir # Unpack the jarfile for patching jar xvf $ecpJarfile rc=$? if [ $rc -ne 0 ]; then echo "Couldn't unpack $ecpJarfile, rc=$rc" else # Check whether this has already been fixed. (We can't count on # exit status of sed; it thinks "no match" on a global replace is # a successful operation.) grep "width:200px" $textBox rrc=$? if [ $rrc -ne 0 ]; then grep "width:100%" $textBox rc=$? if [ $rc -eq 0 ]; then echo "Already patched" else echo "width:200px not found, but not already patched" echo "... this script may need to be updated." fi else # Patch the hardcoded value to full-width relative. # Note that sed s///g returns success even if no instances # were found sed -i "s/width:200px/width:100%/g" $textBox rc=$? if [ $rc -ne 0 ]; then echo "Couldn't patch $textBox, rc=$rc" else # Repack the jarfile, with error recovery original=$(mktemp) cp $ecpJarfile $original{{ }} }}{{jar cvf $ecpJarfile META-INF/MANIFEST.MF * rc=$? if [ $rc -ne 0 ]; then echo "Couldn't repack $ecpJarfile, rc=$rc" mv $original $ecpJarfile else # Remove the temporary backup rm $original # Must do clean restart to pick up modified jarfile restart_server fi fi fi fi # Remove the scratch space cd .. rm -r $tmpdir{{# Return failure code, or 0 for success }} exit $rc |