Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

linux readlink command works from CLI but not from QB3 #1818

bakerj-oclc-org ·
I am currently working on some build configurations that manipulate linux symlinks. I am trying to delete the directory that a symlink is pointing to by using the following command:

rm -fr `readlink symlink` (please note those are back quotes and symlink is the name of the linux symlink pointing to another directory.)

When I run this command from the command line as the same user on the same box in the same directory as the QB agent is running it works as expected. When I run it through QB however the command does not work. It does not error, but it also has no effect. It appears as though 'readlink symlink' evaluates to nothing and so rm -fr executes with no target and does nothing.

I have also attempted the following command and it also works on linux but not from QB.

readlink symlink | xargs rm -fr

At this time, I am currently unable to have the readlink command function correctly.

I am using QB version. 3.1.52
Suse linux 10.3
  • replies 7
  • views 3210
  • stars 0
robinshen ADMIN ·
Since the back tick and pipe line is interpretated by shell instead of the command itself, please write the command like below:
sh -c "rm -rf `readlink symlink `"

And also specify the working directory to be the directory containing the symlink file.
bakerj-oclc-org ·
Worked great. I knew it had to be something with how the command was processed, but wasn't sure how to rectify the problem.

Thanks.
amn ·
I have a more complicated goal similar to this.

I want to have a step that will remove everything from the working directory that is not a symlink called prod or rollback or pointed to by those symlinks.

I'm not sure what the best way to go about this would be or if you have a suggestion on if this is possible.

Here is an example of what works on the Unix commandline: for f in `ls`; do if [ $f != `readlink prod` ] && [ $f != `readlink rollback` ] && [ $f != prod ] && [ $f != rollback ]; then echo rm -rf $f ; fi; done

I would also be open to a Groovy solution for this.
amn ·
I attempted a Groovy solution to this using the Repeat Parameters as follows:

${groovy:

def builds = "null"
def prodVersion
def rollbackVersion

def pout = new StringBuffer()
def perr = new StringBuffer()
def proc = "readlink /home/user/prod/test/prod".execute()
proc.waitForProcessOutput(pout, perr)
logger.info("pout: ${pout\}")
logger.info("perr: ${perr\}")
prodVersion = pout

def rout = new StringBuffer()
def err = new StringBuffer()
proc = "readlink /home/user/prod/test/rollback".execute()
proc.waitForProcessOutput(rout, rerr)
logger.info("rout: ${rout\}")
logger.info("rerr: ${rerr\}")
rollbackVersion = rout

def out = new StringBuffer()
def rerr = new StringBuffer()
proc = "ls /home/user/prod/test".execute()
proc.waitForProcessOutput(out, err)
logger.info("out: ${out\}")
logger.info("err: ${err\}")

out.toString().eachLine {
logger.info("build: ${it\}")
logger.info("prodVersion: ${prodVersion\}")
logger.info("rollbackVersion: ${rollbackVersion\}")
if ( (it != "prod") && (it != "rollback") && (it != prodVersion) && (it != rollbackVersion) ) {
logger.info("build: ${it\} will be removed...")
if (builds == "null") {
builds = "${it\}" \}
else {
builds = "${builds\},${it\}" \}
\}
\}

logger.info("builds: ${builds\}")

return builds

}


This isn't correctly ignoring the prodVersion and rollbackVersion though, even if the values match. I'm not sure if you see something I am overlooking with this though.
robinshen ADMIN ·
How about placing the logic into an external shell script, and call that script with a command build step? That seems a lot easier.
amn ·
It would be easier, but the goal is to keep the logic in QuickBuild because we use it as a central configuration manager for builds and installs so copying and keeping a shell script controlled and on all of the hosts would lead to more issues.
robinshen ADMIN ·
You may put this script in SCM so that it can be checked out to different hosts for execution.