Execute shell script via Jenkins - shell

I have a very simple shell script build-dev.sh. This is how it looks like:
#artifact build script
echo "Running application build for DEV environment"
ng build --deploy-url "js/" --base-href "/my-app-ui/" --configuration=dev
mkdir dist/my-app-ui/js
mv ./dist/my-app-ui/*.{js,svg,css} ./dist/my-app-ui/js
It builds the Angular application, then creates a folder js and then it moves files with the extensions js, svg and css to this folder.
When I execute this script directly by myself it works perfectly.
The issue is that I want the script to be executed by Jenkins. So I have configured "Execute shell" step in my build. Once the Jenkins job is executed, it fails on the execution of the third line of the script (mv command).
mv: cannot stat './dist/my-app-ui/*.{js,svg,css}': No such file or directory
Build step 'Execute shell' marked build as failure
I think it might be related to the fact that I have .*{js,svg,css} in my script.
Can you please tell me what I am doing wrong?

Well, I am still not sure why it does not work, but the problem is in the usage of brackets - {js,svg,css}.
I have replaced the mv command with three lines:
mv ./dist/my-app-ui/*.js ./dist/my-app-ui/js
mv ./dist/my-app-ui/*.svg ./dist/my-app-ui/js
mv ./dist/my-app-ui/*.css ./dist/my-app-ui/js
This works perfectly. It is still some kind of workaround, but it's doing the exactly same, so it works fine for me.

Related

Xcode appears to be modifying paths inside bash scripts during run script build phase

I have a simple script that looks like this:
#!/bin/sh
set -eux
install_folder="${HOME}/Library/MobileDevice/Provisioning Profiles"
mkdir -p "${install_folder}"
if [[ $? != 0 ]]; then
echo "Unable to create destination directory: ${install_folder}"
exit 1
fi
If I run this script from the command line by doing ./my_script.sh everything works as expected. Things go wrong though when I call from Xcode as part of a run script build phase. I currently call it by having "${SRCROOT}/path/to/my_script.sh" in the run script build phase, but the same issue occurs even if I copy and paste the code above in directly.
So what's the issue? Well, it seems Xcode is causing the wrong folder to be created. When I run from the command line, I get a folder named Provisioning Profiles inside ~/Library/MobileDevice/ as expected. When I run from Xcode, the folder is named Provisioning\ Profiles (that \ is literally part of the name).
But it gets weirder. If I change the mkdir line to mkdir -p $install_folder then I'd expect to get a folder called Provisioning inside the MobileDevice folder and a folder called Profiles wherever I ran the command. That's what happens when I run from the command line. If I run from Xcode however, I get a folder Profiles inside MobileDevice but I also get a folder called Provisioning\ Profiles.
I cannot explain this behavior at all. It seems totally counter to everything I (thought) knew about shell scripts.
How is Xcode influencing this? How do I make it stop?
The trick, as always, was realising that there was more to this than I had considered. Xcode wasn't just running this script in the phase, it was doing it with a list of output files set. It was then creating the path for those after it ran the script. The script was behaving exactly as it should have, it was just the extra stuff which made it appear to be broken.
Lesson learned: Xcode will create a folder for output files if it doesn't exist.

Shell build script with ember

I am attempting to write a build script to be used with Facebook watchman and my ember-cli application.
My build script is:
#!/bin/sh
cd ..
ember build
cd ..
cp ./ember-app/dist/index.html ./slim-app/app/templates/app.php
cp -r ./ember-app/dist/assets/ ./slim-app/public/assets/
And my watchman command is:
watchman -- trigger $PWD/ember-app/app 'ember-build' '**' -- sh $PWD/build.sh
Watchman triggers and finds my script fine but when I look at the log I get an error saying ember cannot be found. I'm not really sure why because when i run sh build.sh everything works fine.
Is there any way I could do something like which ember to determine the path to ember and use it directly? I know I can just do which ember and copy and paste that path into the script but I really don't want to do that because I want the build script to work no matter which version of node/nvm I am using.
I'm also open to suggestions to a better way of doing this.
Sounds like a PATH problem. When watchman is first started it captures your PATH environment variable, except on OS X at the moment, due to a bug in our launchd integration.
https://github.com/facebook/watchman/issues/68 has some suggestions for an awkward workaround.
Another possibility is to simply put a line in your build script to set the PATH:
# Add the path to ember in here somewhere
PATH=/usr/local/bin:$PATH

Why my Bash script won't even run if it is deployed in a web app?

I created this simple script that does a backup, I wrote and tested it in Linux, then I copied it in my WebApp WEB-INF/scripts directory so that I could be run via Java Runtime.exec().
#!/bin/bash
JACCISE_FOLDER="/var/jaccise"
rm $JACCISE_FOLDER/jaccisebackup.zip
zip -r jaccisefolder.zip $JACCISE_FOLDER
mysqldump -ujacc -pxxx jacciseweb > jaccisewebdump.sql
zip jaccisebackup.zip jaccisewebdump.sql
zip jaccisebackup.zip jaccisefolder.zip
rm jaccisewebdump.sql
rm jaccisefolder.zip
cp jaccisebackup.zip $JACCISE_FOLDER
But it doesn't. So I tried to copy it from WEB-INF/scripts to my user dir and run it to roubleshoot it. The result is that it comes out with: ": File o directory non esistente" (Means "Unknown file or directory" notice the colon at the beginning). I created another file from scratch, copied and pasted the whole script and it works. I may think that this is related to:
Text encoding
\n\r differences between windows (I use Eclipse on windows to edit everything) and Linux.
How do I solve this deploy problem?
You should check if the file is executable (chmod +x). Then you should check, if your web server allows the execution of external programs. This might be a security problem and it is likely that the web server prevents the execution. Check the logs of the web server. The encoding of the file can be changed with the dos2unix command. In order to debug your script you can add an "set -x" at the beginning, but I think the script does not start at all.

Shell Script Invocation Error with Xcode4 when trying to run a shell script as a build step

Here is what I get when I try to build my Xcode project:
Intermediates/demo2.build/Debug-iphonesimulator/demo2.build/Script-5E564EAC1393823C00BFBA83.sh
/Users/ssbarnea/Library/Developer/Xcode/DerivedData/demo2-fdzrmxojwtekcbeivraccjjadvqz/Build/Intermediates/demo2.build/Debug-iphonesimulator/demo2.build/Script-5E564EAC1393823C00BFBA83.sh: line 2: ${PROJECT_DIR}/local-deploy.sh: No such file or directory
In Xcode I added to the default arget a new Build Phase, a "Run Script" that runs with shell /bin/sh and contains only:
'${PROJECT_DIR}/local-deploy.sh'
I can assure you that the local-deploy.sh file exists in the project directory and that it is executable. It even works if I call it from the console ;)
It should be the following. s/'/"/g :-)
"${PROJECT_DIR}/local-deploy.sh"
Bourne Shell Tutorial - Strong versus weak quoting
Well, I don't think that replacing this will work. You need just put OpenCV.framework folder in proper project folder and I think that is it. I tried out and it worked.

explanations about the code

I have some script and I have no idea what it is doing, will be happy if somebody will explain me:
#!/bin/tcsh
if (-d test) then
svn up test
else
svn checkout http:some address test
endif
cd tests
python test_some.py $argv
P.S can't find info about functions cd and svn
thanks in advance for any help
The script runs a second revision-controlled test script
This script runs a python program which appears to run some tests. The script understands that the test directory is stored in a subversion repository.
If there is a test directory, it updates it in case it has been changed in the repository, perhaps by another svn user or by the same user in a different working directory.
If there is no test directory, it checks it out.
Then it changes its current directory to the working directory.
Then it runs the test script.
I'm a bit confused about one thing. It checks out "test" but then changes its directory to "tests". So either there is a transcription error in the original post or something slightly more complex is going on, like, it somehow assumes that tests exists but not test.
cd is the "Change Directory" command.
svn is a source code repository client.
The script does the following:
if the test folder exists
update it through subversion
else
check it out from subversion repository
go into the tests directory // interestingly enough, it doesn't match the checked out directory name?
run the test_some.py python file, passing the script arguments.
cd, and svn, and python are executable names. cd is the command for changing current directory. svn is the command (executable name) for Subversion source control system. python is the Python language interpreter.

Resources