Run action/script AFTER the binary executed by "bazel run" returns - bazel

I'm wondering if there's a way to run an action or script or program after a bazel run command finishes. Running such a script/program before the bazel run is (in a way) possible via --run_under.
Here's an example use-case:
bazel run //path/to/my:target
Running target generates an output file out in it's cwd (somewhere in the bazel .cache directory)
Run a script that uses the output file out
If it's not possible to get run that script afterwards, is there a way to get the cwd of the binary that was just run? Then it would also be possible to access out from "outside" without bazel.

--run_under is the correct approach to this. You can simply run the command in the script after running what is passed as args to your script that you pass to --run_under e.g.
#!/bin/bash
set -euo pipefail
./prefix_command
bash "$#"
./postfix_command

Related

Does `bazel run` use sandboxing? If not, why not?

From my tests, it doesn't appear that bazel run runs in a sandbox. For example, I ran bazel run //:some_target --spawn_strategy=darwin-sandbox --sandbox_debug, and it didn't generate a new directory in <outputBase>/sandbox/darwin-sandbox.
Am I correct that bazel run doesn't use sandboxing? If so, why not?
bazel run will build the target you pass with sandboxing and caching the same way as bazel build, and then it will run it outside the sandbox. That's the whole point of bazel run.
If you want to run a command inside the sandbox, write a genrule and then bazel build the genrule target.

Jmeter+Jenkins Parameters

I am trying to run jmeter(.jmx) file using Jenkins by passing Number of Threads as a Parameter. Build getting success but .jmx file is not running. And also not showing any error in console.Following are my setup
In Jmeter Thread properties --Number of thread (Users)- ${__P(USERS,1)
In Jenkins job Created build string parameter -- USER_COUNT
Build using Execute shell and following is my command
cd /apache-jmeter-2.13/bin
./jmeter.sh -n -t /jmxFiles/Jbpm6Rest3Jenkins1.jmx -l /jmxFiles/SIP.jtl -JUSERS=%USER_COUNT%
While starting build passing USER_COUNT value from Jenkins
Following is the Jenkins console output
Jenkins Console Output
Not sure where i am doing wrong.
Note: Not using Ant/Maven to run jmx file.
As the other answer mentioned, change the %_USER_COUNT% to ${USER_COUNT}.
But is there any specific reason you are not using Ant/Maven?
Eventhough you should be able to run your jmeter test using a simple shell script, using Ant/Maven might make your life easier while generating report, charts etc.
I would advise you check the below links.
http://www.testautomationguru.com/jmeter-continuous-performance-testing-part1/
http://www.testautomationguru.com/jmeter-continuous-performance-testing-part2/
From the output, seems you are running a shell build step ($ /bin/sh -xe ....), which means your Jenkins runs on Linux (?). Also the paths use forward slash (/)....
You should put the string ${USER_COUNT} as part of your command (%USER_COUNT% is windows style).
I hope this helps.

Executing custom shell script to build in jenkins

I have setup a jenkins job to build my project. I have a jake.sh file in my project and the code is pulled from github. I want "npm install" command to be executed and then jake.sh to be executed once the the code is checked out.
How can I configure this in jenkins? I have tried givin ./jake.sh and jake.sh in Build->Execute Shell section
According what you tell I think the problem can be
The script is not marked as a executable. In this case add in Build -> Execute Shell (in case you have linux) sudo chmod 777 path_to_script/jake.sh.
The script is not in the base directory. Remembeber that when you execute a bash script, the current directory is /path_to_job/workspace. So you have first to move to the script folder (cd path_to_script) or specify the path when running it: ./path_to_script/jake.sh.
I hope this solves your problem.
A workaround for shell scripts can be to run the script as
bash ./jake.sh
instead of
./jake.sh
Then you don't have to do chmod. Useful when you wipe the workspace before every build.
In the same manner, if you have a nodejs shell script or python script, you can run node myscript.js / python myscript.py.

Jenkins how to rename war file

I have deployed a war file in a remote machine using Jenkins. Now I want to rename the war file through jenkins before it extracts the work folder? How can this be done? I tried post deployment action -> execute shell and mv file.war to new-file.war but it returns an error saying : mv: cannot stat `file.war': No such file or directory.
Suppose there was something wrong with my path it would not even have gone to remote location. but for me, after scp' ing it to remote location thru jenkins, and when i try to do a mv, it fails.. What could the reason be??
Adding additional Step of Execute shell during Add build Step or Add post-build action stage, normal renaming shell command mv can be used to rename artifacts.
Note: Make sure use the correct path(Relative to project/workspace root)
Your mv command is probably executed in another directory than the one you are expecting.
To know the directory your script is running in without reading the jenkins / plugin documentation add
echo "pwd of script is: " `pwd`
to your shell script and inspect the output of the jenkins build - that way you can be sure about the directory the script is run in.

Command are ignored after ant command in batch file

Following is the bat script code block on which i am working on:
ECHO off
IF NOT EXIST "%ANT_HOME%" (
SET ANT_HOME=%~dp0%build\apache-ant-1.8.2
SET ANT_BIN=%~dp0%build\apache-ant-1.8.2\bin
SET PATH | FIND "%ANT_HOME%;%ANT_BIN%"
)
cd "build\Run"
ant -q
cd ../..
echo "Program Terminated!"
exit
Now, my build.xml file is inside this build\Run folder so that i am first navigating to build/Run before running ant -q command (NOTE: I don't want to change this method of navigating).
The moment ant -q command is executed following things happen:
Set the environment variables as the condition.
Change directory to build\Run.
As my build.xml is inside the Run directory the ant -q command run correctly.
Ant executed correctly and not ant script terminates.
Now my current path will be build\Run ! correct <= Here i don't want this after ant is terminated, instead i want to come out from build\Run that's why i used cd../..
But the problem is I am not able to execute the commands after ant -q. This happens be the program control goes from BATCH => ANT.
Is there any way to execute my command after ant command from bat script itself ?
You may find that the ant being run is a batch file itself, in which case it simply chains to it (no return).
You should try this instead:
call ant -q
Calling a batch file (as opposed to chaining) will correctly return to the point after which you called it.

Resources