Script is not running in Xcode build phase - xcode

In my package.json file I have a script that I'm running
node src/validateRun.js
I'm trying to run that script in the Xcode build phase. the script is located in the src/ so the build is successful but the script is never running.
Here is my build phase config:
shell: /bin/sh
SRC_DIR="../src/"
node "$SRC_DIR/validateRun.js"
is there any reason why the script is not running ?

Apparently instead of execute node file.js you should type it like this:
/usr/local/bin/node your_file.js

Related

Multiple maven install commands in Linux

I am running an azure pipeline for a maven project which has windows commands for maven installation, by calling multiple methods i.e.,
call mvn ... clean install
call mvn ... clean package (authentication)
call mvn ... clean package (restapi)
The build environment is linux Hence I am converting all the commands in the batch file to sh commands. For maven installation I initially added a maven installation task by mentioning the path and commands in the task. This failed.
So I am currently changing the windows commands to sh commands. The other commands except for maven installation have been converted using a batch to sh commands reference article.
Could some one guide me to convert the above mentioned installation commands to sh commands?
If the Apache Maven has been installed and added to the system path on the agent machine where your pipeline runs, you can just try directly calling the mvn command in the bash script, like you call it on Windows.
For example:
mvn ... clean install
mvn ... clean package (authentication)
mvn ... clean package (restapi)
Before you execute the bash script in the pipeline, you firstly should try and debug it on your local machine to make sure it can work as expected on the local machine. Then move the bash script to the pipeline on Azure DevOps.
If the bash script runs failed in the pipeline, for us to investigate this issue further, please share us with the complete debug logs of the failed pipeline run. To get the debug logs, you need to set the pipeline variable System.Debug to true, then trigger the pipeline.

sbt dist works in terminal but not with Jenkins as shell script

I am completely new to both sbt and Jenkins. I am trying to construct a build plan using Jenkins piplelines. The following commands run just fine within shell script: sbt compile & sbt package
However, sbt dist does not work. I get the error not a valid command
What is puzzling me, I can run the command from terminal just fine.
For what its workth, here is the contents of jenkinsfile (I know sbt dist should be in build, but I am still experimenting):
pipeline {
agent any
stages {
stage('Build') {
parallel {
stage('Build') {
steps {
sh 'echo "Compiling... "'
sh 'sbt compile'
}
}
stage('Deploy') {
steps {
sh 'echo "Deploying... "'
sh 'echo "packaging.. "'
sh 'sbt dist'
}
}
}
}
}
}
Jenkins 2.89.1, sbt tried both: 0.13 and 1.0.x
I see now from comments that you are working on Play application, so it is clear now where the dist task comes from.
In Jenkins first thing that you need to make when you running SBT tasks is that you have loaded to SBT your build.xml of your project. In your shell script it is not actually visible whether you are in the root project folder or not.
Also Jenkins has integration with SBT better then just running it through shell script. You need to add this plugin to Jenkins first. Look at the attached screenshot, where part of one of my Jenkins projects is shown:
There is a special kind of build step in Jenkins. In your project configuration you should see it under the "Build step" dropdown:
I believe you should start from there. If you still need to run through shell script make sure you also cd /path/to/your/project folder before running SBT commands.
I accepted #Alexander Arendar answer, as it is the correct answer. I just want to elaborate on how I got it right, so it can be useful for others.
The answer as #Alexander mentioned is If you still need to run through shell script make sure you also cd /path/to/your/project folder before running SBT commands. I was actually doing that. But what I was completely oblivious to, is that cd to directory and running sbt dist must be withiin the same jenkins step. I was doing that in two separate steps, and ending up running sbt dist in the original directory.
One worthy note is, cd to project was needed only for sbt dist since it comes with Play. Standard sbt commands (e.g.: sbt compile) were running fine outside the play project directory.

Jenkins execute shell not able to find gradle commands

I am trying to trigger gradle command in execute shell of a particular node from jenkins master and it's trowing an exception as-
gradle: command not found
Build step 'Execute shell' marked build as failure
However, gradle command works if am trying to execute shell in the same node itself under local workspace.
What I understood-
Triggering any job from remote by default try to search executable like 'adb', 'gradle' in /usr/local/bin of node machine (Macintosh)
read-write access should be there for '.gradle' folder
What I have done-
added .gradle inside /usr/local/bin of slave
granted read-write access to .gradle
Here, both node-jenkins and master-jenkins have gradle v2.5 installed. Why execute shell triggered from master jenkins not able to find gradle in slave jenkins, any help would be appreciated.
try run env before your try to run gradle. and compare it to env from the command line. I think that Jenkins use another path.
I was also facing same issue where gradle command working fine on machine where jenkins is installed but the same command was not working on slave.
Solution:
You need to set GRADLE_HOME on slave.
Most important: set PATH into the slave configuration [copy the exact PATH path from slave machine and copy it into Jenkins slave configuration under Jenkins--> Manage Jenkins--> Manage Node--> NodeName(your node name)--> Configure and search for Node Properties-->Environment variables]
save
In my case I have added additional PATH env variable, then it worked.
I was also facing same issue
verify you add Gradle Plugin to your jenkins
Verify that you inside the Folder where exist the "gradle.build" file
my example: the location of my gradle.build was insifr the foulder automation-api

nohup: failed to run command `sh`: No such file or directory

I have the following pipeline script in Jenkins:
node {
withMaven(globalMavenSettingsFilePath: '/my/path/apache-maven-3.2.2/conf/settings.xml', jdk: 'JDK 1.8.0u92', maven: 'apache-maven-3.2.2', mavenSettingsFilePath: '/my/path/apache-maven-3.2.2/conf/settings.xml') {
sh '/my/path/apache-maven-3.2.2/bin/mvn clean install'
}
}
For this, I am getting:
nohup: failed to run command `sh`: No such file or directory
ERROR: script returned exit code -2
Why is this?
I am sure that the path to my Maven installation is correct. When I run a job without the pipeline, Maven builds with no errors and I can see that it uses the same path.
This might be the result of modifying PATH.
Check your script and Global Properties and remove modifications to PATH. It is now recommended to use PATH+extra instead. It would still be picked up, but without breaking actual PATH.
Related issue on Jenkins: https://issues.jenkins-ci.org/browse/JENKINS-41339
In the end, I used shell instead of sh and it worked. No idea why, they don't have a proper API.
I would suggest to use it like this:
withMaven(
maven: 'M3',
mavenSettingsConfig: 'maven-settings-for-the-task',
mavenLocalRepo: '.repository') {
// Run the maven build
sh "mvn clean install"
}
Apart from that I would not use absolute paths to global settings.xml nor to user settings.xml. I would prefer using usage of "Config File Provider Plugin" which has the advantage to have the settings.xml on Master and available on all nodes.
See also the documentation: https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Maven+Plugin
This error comes when you are trying to run script copied from windows machine to unix machine.
YOU need to change the format to unix using : dos2unix <scriptname.sh> and the run your script in unix ./<scriptname.sh>

Running a Grunt task before MVN in a Build pipeline?

This question is very specific to Bluemix DevOps.
I have a Java backend application that has a sizeable JavaScript front-end. So I created a GRUNT task to do the needed: uglify, minify, CDNify etc. My current setup is to have the Bluemix build just running mvn -B package and the Grunt task beforehand as a script on my local machine:
#!/bin/bash
grunt build
git add --all
git commit
git push origin master
But that precludes any edit using the online editor. So I'd like to have both task to run by the pipeline. I see 3 options:
Run both tasks in one build block triggered by git push as separate tasks
Run them in one build script triggered by git push
Run 2 pipeline steps, the first triggered by git push, the second by the completion of the first
something else
I haven't tried it yet (shame on me), just wanted to ask if someone did that before (If yes - cool, if no I will post my findings later on)
Solved it. This is what I tried:
modify the script in build and prefix with npm install npm or mvn (depends on what I selected) wasn't found)
add 2 jobs to one build stage, one grunt one maven (the deploy task would not find the war file)
Use 2 pipeline stages (see picture below) : Horray --- that worked.
None of the build steps required setting a directory, which is a little trap, since mvn sets target as default directory, so remove this. The script for Bower/Grunt is this:
#!/bin/bash
npm install
grunt build
the script for the maven task:
#!/bin/bash
mvn -B package
works like a charm (just be careful not to add npm modules you don't actually need, it slows the build quite a bit)

Resources