I've been trying to debug this issue all day with no success.
Issue: Bash script executes successfully on a Linux CentOS7 VM (jenkins build agent) but fails during Jenkins build.
Here's the simple script.
#! /bin/bash
echo "before beyond compare command"
bcompare #"bc_report.ps1" "./Output_Base/<Folder_Name>" "./Output_Compare/<Folder Name>" "Report.html"
echo "after beyond compare command"
The output in the Jenkins build log is just:
before beyond compare command
after beyond compare command
When viewing the VM during the Jenkins build, I'm not seeing an artifact being produced. The user during the Jenkins build is Root, when executing the script locally, I'm also doing so as Root with success.
I'm pretty sure this is a Jenkins issue, just can't seem to figure it out. Anyone seen something similar?
Beyond Compare 4 for Linux requires an X-Window/GUI session to run, even for scripts. As a cron job or in an SSH terminal without an X-Window client, Beyond Compare for Linux scripts will fail to run. This might be what is causing your Jenkins job to fail.
Beyond Compare 4 for Windows doesn't have the GUI session requirement for scripts. Beyond Compare 4 for Linux and macOS both require a GUI session for scripts. Removing the GUI session requirement for scripting on Linux and macOS is on the feature request list for a future version.
Related
So after spending half a day as our surprise jenkins devops guy, I'm not sure if this scenario is even possible.
We have a linux Jenkins server that runs a groovy file to build some of our software. Recently we moved from dropbox to onedrive and one of my tasks is to change all our CI apps to upload files to onedrive. Using appveyor and powershell I was able to do this, but Jenkins is giving me problems. I was hoping to re-use the powershell scripts I wrote for appveyor, tweak them, and use them in the Jenkins pipeline. I've installed the Powershell plugin on our Jenkins server, but it's still not finding powershell. I've tested the GetAccessToken.ps1 script locally (but I'm on w10), and it's fine.
Groovy code snippet
stage('Deploy')
{
environment
{
ONEDRIVE_ID = credentials('OneDriveClientId')
ONEDRIVE_SECRET = credentials('OneDriveSecretKey')
ONEDRIVE_TOKEN = powershell "Common/Build/GetAccessToken.ps1 ${ONEDRIVE_ID} ${ONEDRIVE_SECRET}"
}
steps
{
echo 'Deploying Code....'
sh "chmod +x Common/Build/UploadToOnedrive.ps1"
powershell "Common/Build/UploadToOnedrive.ps1 -t ${ONEDRIVE_TOKEN} -s bootloader/redacted/Build/redacted-f redacted -v ${VERSION} -b ${BRANCH_NAME}"
}
}
Error
Caused: java.io.IOException: Cannot run program "powershell" (in directory "/var/lib/jenkins/workspace/test_branch"): error=2, No such file or directory
I've tried about 10 different ways of calling the script, based on other SO posts and jenkins.io posts, and I get varying degrees of failure. I'm wondering if I need a Windows slave to run powershell (although I thought the plugin would allow me to). Last resort I'll just try to alter the old bash scripts to upload using curl but I was really hoping to use the powershell scripts.
Oh, and here's my PATH. I think I read that pwsh/powershell gets installed in /usr/local/sbin or /usr/local/bin so that shouldn't be the issue
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Thanks to Shane's sanity check, I was able to install pwsh on the Jenkins ubuntu server and then my groovy pwsh steps started working. I'm still having some issues passing variables but that's for another topic. I'm now able to use scripts like this in my groovy script
environment {
ONEDRIVE_TOKEN = pwsh (script: "Common/Build/GetAccessToken.ps1 ${env.ONEDRIVE_ID} ${env.ONEDRIVE_SECRET}", returnStdout: true)
}
Update; here is how I'm able to call a powershell script from groovy with variables
sh 'pwsh Common/Build/UploadToOnedrive.ps1 -t $ONEDRIVE_TOKEN -s "Release" -f "testname" -v $VERSION -b $BRANCH_NAME'
I haven't been able to find a similar question, but I can't imagine this is an issue that comes up too much.
At my workplace I've decided to switch over to a full Linux experience by using Cygwin, over what I was previously using, Git Bash.
The only slight drawback is that we have a script written in Ruby that deploys changes to our site. I can run this from my Git Bash terminal no problem, but not Cygwin as there doesn't seem to be a Ruby installation on here. I've learned about sending standard output to other terminal windows, but I've only been successful when both terminals have been the same shell.
What I'd like to do is the following:
1. Type a command into Cygwin that opens a Git Bash terminal and automatically runs ./deploy.sh on that Git Bash terminal upon opening.
2. If possible, also pass in an argument in the same command, that the script expects upon running. (In this case it's whether we want to deploy to our staging or production server).
Is this possible? So far I can get what looks to be a Git Bash terminal to open and prompt me for the server, but when I enter it, it does not work. I get an error with regards to a command within the script not being found. Thing is, running this same ./deploy.sh script in a Git Bash terminal that I open myself works perfectly as it always has. The Git Bash terminal that is being opened by Cygwin does not appear to have all of the capabilities of a Git Bash terminal I open 'the normal way'.
The command I am running so far from Cygwin is as follows:
/cygdrive/c/'Program Files'/Git/git-bash.exe "./deploy.sh"
I understand there is probably a way of getting this to work by installing Ruby via Cygwin but I'd like to mess around with my work environment as little as possible in case I somehow affect my ability to deploy my work... and besides, Git Bash definitely runs this script without an issue so I can't see why I would need a duplicate installation.
Many thanks!
I'm new to this area and was trying to run the following commands from jenkins:
npm install
grunt quickStart
So far I've a jenkins running on a window machine as a window service and I've also installed NodeJs plugin for jenkins.
However, I'm stuck and quit confused following instructions here, its asking me to to add one or mode nodeJs installation and I could not find those setting and not even sure if I even need them in the first place.
Here is the bit that's asking me to do:
I cannot see this setting for the jenkins job I create. Is there an easy way to run those command in jenkins from a .bat or .sh script, a .bat would be recomended since I'm on window machine.
Note : I've already checked out a project using git in jenkins!!!
Thanks
"its asking me to to add one or mode nodeJs installation and I could not find those setting and not even sure if I even need them in the first place."
I don't think you need that I have pointed jenkins to the node installation folder an nothing more.., for this you go to Manage Jenkins->Configure System->NodeJS->NodeJS installations.. type in any name you like and point to where the node home folder is.
...cannot see this setting for the jenkins job I create...
Once you have configure that in your jenkins configuration you should have that configuration available like so:
...Is there an easy way to run those command in jenkins from a .bat or .sh script, a .bat would be recomended since I'm on window machine
I'm sorry don't get what commands are you referring to...
so summarizing :
you have to tell jenkins where you have your node installation
use that configuration in your jobs
hope this helps...
The way I made it, was trough execute shell, as the build tool for nodejs is npm, I simply wrote a shell script that instructs jenkins to run npm install in the workspace directory inside jenkins where it clones the git repository and then to zip and move the package if successful to another folder.
I am looking for a Jenkins plugin that makes it execute simple shell script into a given machine.
A possible execution of this plugin would be:
Given hostname,username,password, execution folder, and script --> connect to the machine and execute the script.
Can I do it without pre-configuring the machine as Jenkins slave?
I've checked out ssh-plugin and publish-over-ssh but they don't offer doing such thing without preconfiguring the hosts.
So I couldn't find the right built-in solution for Jenkins but Python Fabric is an interesting direction
I am following this tutorial that is like the hello world for post-commit
I am using Ubuntu 10.04. I installed svnnotify and ran $ which svnnotify which output:
/usr/bin/svnnotify
so I changed the path in the turorial from /usr/local/bin/svnnotify to /usr/bin/svnnotify
I also tried changing the line: #!/bin/sh to #!/bin/bash since bash is the login shell in ubuntu 10.04.
I tried to run it the way the tutorial originally had it, with my changes, and combinations of the two.
Every time the commit is successful but I get
Warning: post-commit hook failed (exit code 1) with no output.
The original way had output not found
I am very new to linux and shell scripting and have exhausted everything I can think of. What am I doing wrong?
Get the script working and tested before trying to run as a commit hook. I expect that your problem is something to do with the script, maybe not being marked as executable, environment wrong, etc.. i.e. if you can't get it to run successfully from the command line, this is more of a unix/shell question and doesn't really have anything to do with SVN (yet).
I'm not sure whether this applies in the Linux world, but in the Windows versions of SVN I've used, the code which runs the hook scripts only captures STDERR. If your hook script is only writing messages to STDOUT, that would likely explain the "No Output" warning.