AppCenter Android Build - Custom shell script appcenter-post-clone script fails with command not found - visual-studio-app-center

I am trying to build native android app on Azure AppCenter. I have custom appcenter-post-clone.sh to be executed just after the source code clone step. The script executes, but fails with command not found. Here is a sample script and error output.
appcenter-post-clone.sh
#!/usr/bin/env bash
set -x
ls
pwd
ls -l
Build output
==============================================================================
Task : Shell script
Description : Run a shell script using Bash
Version : 2.165.2
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/shell-script
==============================================================================
[command]/bin/bash /Users/runner/work/1/s/app/appcenter-post-clone.sh
/Users/runner/work/1/s/app/appcenter-post-clone.sh: line 2:
: command not found
/Users/runner/work/1/s/app/appcenter-post-clone.sh: line 3: set: -
: invalid option
set: usage: set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
/Users/runner/work/1/s/app/appcenter-post-clone.sh: line 5: ls
: command not found
/Users/runner/work/1/s/app/appcenter-post-clone.sh: line 6: pwd
: command not found
/Users/runner/work/1/s/app/appcenter-post-clone.sh: line 7: ls
: command not found
ls: illegal option --
usage: ls [-#ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1%] [file ...]
The pipeline is running on a mac agent. I do not understand if I am using the correct bash shell to execute the scripts.

Related

How to execute mongodb commands inside the bash script

I'm trying to run mongo commands through my bash script file.
I have sample.sh -- run with ./sample.sh
I want to run below command inside my sample.sh file. It is bash script.
I want to mongo commands run inside the file, not inside the shell.
kubectl exec $mongoPodName -c mongo-mongodb -- mongo db.createUser({user:"admin",pwd:"123456",roles:[{role:"root",db:"admin"}]})
I get the error below :
./generate-service-dbs.sh: line 37: syntax error near unexpected token `('
./generate-service-dbs.sh: line 37: `kubectl exec $mongoPodName -c mongo-mongodb -- mongo db.createUser({user:"admin",pwd:"123456",roles:[{role:"root",db:"admin"}]})'
Don't you have to run command with --eval?
kubectl exec $mongoPodName -c mongo-mongodb -- mongo --eval 'db.createUser({user:"admin",pwd:"123456",roles:[{role:"root",db:"admin"}]})'

docker: invalid reference format | error | cloud vm ubuntu

I created a vm (ubuntu-18.04 ) on Azure cloud and installed docker having a version 17.09.0-ce. if I execute the docker commands like docker images, docker version from the bash it works.
However, when I try to execute the same commands from shell script like below, it throws errors.
Below is a script and an output. I also tried to run nginx:alpine but results were same.
test.sh script
#!/bin/bash
#
echo "=== docker version==="
docker images
echo "==== Starut running a jmeter/image ===="
docker run "justb4/jmeter:latest"
echo "==== Finish ===="
output
2020-05-24T21:39:58.1073920Z ========================== Starting Command Output ===========================
2020-05-24T21:39:58.1075676Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/59e915fd-ea8a-4e36-8abb-8574d7a5bbf9.sh
2020-05-24T21:39:58.1141394Z === docker version===
2020-05-24T21:39:58.1221659Z docker: 'images
2020-05-24T21:39:58.1222312Z ' is not a docker command.
2020-05-24T21:39:58.1223386Z See 'docker --help'
2020-05-24T21:39:58.1224742Z ==== Starut running a jmeter/image ====
2020-05-24T21:39:58.1300191Z docker: invalid reference format.
2020-05-24T21:39:58.1300949Z See 'docker run --help'.
2020-05-24T21:39:58.1308872Z ==== Finish ====
2020-05-24T21:39:58.1326008Z
2020-05-24T21:39:58.1391207Z ##[section]Finishing: Bash Script
With Windows or DOS-style line endings , each line is terminated with a Carriage Return followed by a Line Feed character. If a script file was saved with Windows line endings, Bash sees the file as
#!/bin/bash^M
^M
cd "src"^M
Try running dos2unix on the script solved the problem.
http://dos2unix.sourceforge.net/

Jenkins running Linux shell program does not reccogize commands

I have the following code running on my jenkins build step: "execute shell"
#!/bin/sh
workspaceDirectory=WORKSPACE
appName=ClaimCenter
perl WORKSPACE/directory/scripts/FileLoaderDoItTwiceFinal.pl $workspaceDirectory $appName
curl --ntlm --user myUserName:myPassword --upload-file WORKSPACE/directory/test/ClaimCenterUnmatchedProperties.csv https://sharpoint/share/sharesight/TrainingManuals/RTC/PropertyFileAnalyzer/filename.csv`
appName=ContactManager
perl WORKSPACE/dircectory/scripts/FileLoaderDoItTwiceFinal.pl $workspaceDirectory $appName
curl --ntlm --user myUserName:MyPassWord --upload-file WORKSPACE/CliamCenterBatch/test/ContactManagerUnmatchedProperties.csv
https://sharpoint/share/sharesight/TrainingManuals/RTC/PropertyFileAnalyzer/filename.csv`
Jenkins builds for a long time so it is very difficult to test repeatedly but after the build opperations happen, the following is output to the jenkins console:
[TEST-SAMPLE-BUILD-CLAIMS_Dev_Tools_blucas-DEF] $ /bin/sh/tmp/hudson4025671051509183982.sh
/tmp/hudson4025671051509183982.sh: line 5: perl: command not found
/tmp/hudson4025671051509183982.sh: line 6: curl: command not found
/tmp/hudson4025671051509183982.sh: line 10: perl: command not found
/tmp/hudson4025671051509183982.sh: line 11: curl: command not found
/tmp/hudson4025671051509183982.sh: line 12: https://sharpoint/share/sharesight/TrainingManuals/RTC/PropertyFileAnalyzer/filename.csv` : No such file or directory
please help me understand why this build is not understanding these commands
The error message is telling you that perl and curl binaries couldn't be found, which means that the environment for your script does not have PATH environment variable set.
To fix this, use the full paths to the binaries, instead of just their names. eg:
/usr/bin/perl WORKSPACE/directory/scripts/FileLoaderDoItTwiceFinal.pl $workspaceDirectory $appName
/usr/bin/curl --ntlm --user myUserName:myPassword --upload-file WORKSPACE/directory/test/ClaimCenterUnmatchedProperties.csv https://sharpoint/share/sharesight/TrainingManuals/RTC/PropertyFileAnalyzer/filename.csv`

Configure: error: cannot run /bin/sh

I am trying to build GNU toolchain for OpenRISC by following the guide given at http://openrisc.net/toolchain-build.html on Fedora Virtual Box Image.
I am getting error saying
Configure: error: cannot run /bin/sh ../gcc-svn/config.sub
when I try to configure gcc.
I am new to Linux. I could not find any solution online. Any help to solve the issue is highly appreciated.
Open config.sub with a hex editor to see if the line endings are \r\n instead of just \n. If so, make a backup of the entire folder and then type:
dos2unix *
That will change all line endings from \r\n to \n, and it does it in place, overwriting each file. Then, again try:
./configure (with any options you desire)
I had this problem on cygwin for Windows where GitHub had converted all files to \r\n, so I had to convert them back with dos2unix.
1.check and install libtools
yum install libtool
yum install libtool-ltdl
yum install libtool-ltdl-devel
2.try run "../gcc-svn/config.sub" through shell
/bin/bash ../gcc-svn/config.sub
see if shows as follows:
[root#centos jemalloc]# /bin/bash ./config.sub
: command not foundine 6:
: command not foundine 8:
: command not foundine 30:
: command not foundine 31:
: command not foundine 39:
: command not foundine 42:
: command not foundine 50:
: command not foundine 57:
: command not foundine 59:
: command not foundine 72:
: command not foundine 82:
: command not foundine 85:
'/config.sub.bak: line 88: syntax error near unexpected token in
'/config.sub.bak: line 88: ` case $1 in
3.find the system config.sub
find / -name config.sub
it shows:
/usr/share/libtool/config/config.sub
compare the two config.sub to see if they are similar.
4.replace config.sub with system file
mv ../gcc-svn/config.sub ../gcc-svn/config.sub.bak
cp /usr/share/libtool/config/config.sub ../gcc-svn/config.sub
mv ../gcc-svn/config.guess ../gcc-svn/config.guess.bak
cp /usr/share/libtool/config/config.guess ../gcc-svn/config.guess
make to see if it works out.
What is the first line of your ../gcc-svn/config.sub file? I'm guessing it may have a typo. It should be
#!/bin/sh
and not
/bin/sh
If it is
#!/bin/sh
Make sure that the file /bin/sh exists and is executable
ls -l /bin/sh
Should show something like
-rwxrwxrwx 1 root root 4 Feb 3 2009 /bin/sh

linux cp command different behavior between cmd line and shell script.

When building gcc-4.8.1, I met a cp command as following:
#!/bin/sh
set -x
fname="cp.sh"
cp -v $fname.{,.bk}
It will occurs error when execute this script:
<29>pli[1050]#~/workspace/shell*0 > sh cp.sh
+ fname=cp.sh
+ cp -v cp.sh{,.bk}
cp: missing destination file operand after âcp.sh{,.bk}â
Try 'cp --help' for more information.
<30>pli[1051]#~/workspace/shell*0 >
But when type it on cmd line directly, it works well as expected. It is very in comprehensive to me.\n
<28>pli[1049]#~/workspace/shell*0 > cp -v cp.sh{,.bk}
cp.sh -> cp.sh.bk
<29>pli[1050]#~/workspace/shell*0 > ^C
You need to build gcc with "bash". On Ubuntu derived distributions "/bin/sh" in not linked to "/bin/bash" (but to "/bin/dash"); this is documented in the Ubuntu wiki here. I would suggest using a "ppa" if possible.

Resources