Suppress script in the Jenkins post build task - jenkins

I am using Jenkins Post build task plugin to execute a bash script. The script is running fine, but the entire raw script is printed on the Jenkins console. Check section 3 in the image.
How can I avoid the script from getting printed on the Jenkins console?

Related

Execute shell giving error in Jenkins Freestyle job

Whenever I am trying to do execute shell command in freestyle job in Jenkins, however when I try to do same thing while from pipeline, it is running successful.
Following is the error which I am getting in freestyle job:
It seems that the drive is full and there is no space left to execute this shell command. See this log:
So what you should do is to make sure that there is enough space on the drive where you run the script/command is available. Maybe you could switch to another partition or delete temporary or unused files.

Jenkins: Running groovy script with ant commands

I have a groovy script with ant commands on it. The script is successfully run in my local machine but when I tried it with Jenkins the groovy script always fail. Jenkins always return error that "ant can't create task or type p4Change". I already added Apache ant support in the global configuration. How do I configure ant to successfully run the groovy script I have. Any idea. Thanks.
Sample code snippets:
I have execute.groovy file with ant commands
ant=new AntBuilder()
def checkChanges {
ant.p4change(description:"Checking",port:'perforce:1666',user:optional,view:"'${workspace}'...")}
And I created a batch file that will run the execute.groovy file
call groovy execute.groovy project bopolz18 -c bopolz18.Workspace 150718
In my machine this works well but in Jenkins when I execute the batch command it fails giving the error mention above.

How can I add a Jenkins post action to execute two different scripts once the build successed or failed exclusively?

I want to execute a shell scripts if the Jenkins job build successful or another scripts if the Jenkins job build failed.
I added the post build task plugin, but it seems only can execute a shell in all status or just successful status, cannot specify another shell script to be run once build failed, the two scripts should be run exclusively.
are there anyone can help me on this?
use Post Build Task plugin for conditional steps
I use Conditional BuildStep Plugin and Text Finder Run Condition Plugin to execute steps when the build fails.
But there's a limitation with this method: You have to find a text that is displayed ONLY when your build fails.
See the pictures below:
I add exit 0 at the end of the script to force the build to be successful so that the program can execute the next step, which is Conditional steps(multiple).
You will see Execute script after a failed build. being displayed on console output when the job fails.
This is the execution result.
You will also need to find a text that is displayed ONLY when the first step succeeds so that you can trigger another script.

Execute a script from jenkins pipeline

I have a jenkins pipeline that builds a java artifact,
copies it to a directory and then attempts to execute a external script.
I am using this syntax within the pipeline script to execute the external script
dir('/opt/script-directory') {
sh './run.sh'
}
The script is just a simple docker build script, but the build will fail
with this exception:
java.io.IOException: Failed to mkdirs: /opt/script-directory#tmp/durable-ae56483c
The error is confusing because the script does not create any directories. It is just building a docker image and placing the freshly built java artifact in that image.
If I create a different job in jenkins that executes the external script as
its only build step and then call that job from my pipeline script using this syntax:
build 'docker test build'
everything works fine, the script executes within the other job and the pipeline
continues as expected.
Is this the only way to execute a script that is external to the workspace?
What am I doing wrong with my attempt at executing the script from within
the pipeline script?
The issue is that the jenkins user (or whatever the user is that runs the Jenkins slave process) does not have write permission on /opt and the sh step wants to create the script-directory#tmp/durable-ae56483c sub-directory there.
Either remove the dir block and use the absolute path to the script:
sh '/opt/script-directory/run.sh'
or give write permission to jenkins user to folder /opt (not preferred for security reasons)
Looks like a bug in Jenkins, durable directories are meant to store recovery information e.g. before executing an external script using sh.
For now all you can do is make sure that /opt/script-directory has +r +w and +x set for jenkins user.
Another workaround would be not to change the current directory, just execute sh with it:
sh '/opt/script-directory/run.sh'
I had a similar concern when trying to execute a script in a Jenkins pipeline using a Jenkinsfile.
I was trying to run a script restart_rb.sh with sudo.
To run it I specified the present working directory ($PWD):
sh 'sudo sh $PWD/restart_rb.sh'

Access Jenkins build log within build script

How would you go about accessing contents of the build (console) log from within a running build script?
I have a deploy script that runs, logs into a series of servers and runs scripts on those servers. I need to obtain certain output from some of those remote scripts and use them later in the build process and also in the completion email.
You can do something like this in the Post Build section, but I don't think you can do it earlier in the job. With the groovy post build plugin you can get information from the console log:
if(manager.logContains("text to find")) {
do something
}

Resources