Run shell script
Asked by Mustafa ahmed:

I need to run my shell script to modify some files without using pipelines.  
Is that possible?


Answers:
author: Patrik S
body: Hello [@Mustafa ahmed](/t5/user/viewprofilepage/user-id/5117636) ,

Welcome to Atlassian Community!

In case you want to run the script within Atlassian infrastructure, you will indeed need to use Bitbucket Pipelines, or clone the repository and run the script on your local machine and then push back to bitbucket whatever changes executed by the script in your local repo.

Thank you, [@Mustafa ahmed](/t5/user/viewprofilepage/user-id/5117636) !

Patrik S

comments: author: Mustafa ahmed
body: Hello [@Patrik S](/t5/user/viewprofilepage/user-id/4603309) ,

thanks a lot for your answer.

I have tried a script on my Pipeline to edit a file and commit that change   

here is my yml config:  

> pipelines:  
> custom:  
> new_publish:  
> - step:  
> name: new publish  
> script:  
> - echo "This step runs once you click the 'Run' button"  
> - /bin/sh Build_script.sh  
> - echo "git commands"  
> - git add .  
> - git commit -m "change 122"  

<br />

and here is my Build_script.sh:  

> #!/usr/bin/env bash  
> #  
> # echo "You need define the APP_ENV variable "
>
> <br />
>
> APP_ENV="production"
>
> ENTITLEMENTS_PLIST_USER=Apps/UserApp/Cura.UserApp.iOS/Entitlements.plist
>
> <br />
>
> if \[ -e "$ENTITLEMENTS_PLIST_USER" \]  
> then  
> echo "Updating Env to $APP_ENV in Entitlements.plist"  
>
> plutil -replace aps-environment -string $APP_ENV $ENTITLEMENTS_PLIST_USER  
> echo "File content:"  
> cat $ENTITLEMENTS_PLIST_USER  
> fi
>
> #git add .  
> #git commit -m "change 1"

<br />

<br />

<br />

but it does not work  
I get this error:  
"Build_script.sh: 15: Build_script.sh: plutil: not found"  

please not that I am using that script on Appcenter.  

<br />

My question is that possible to edit files using pipelines? or it's just for building testing \& deploying.  

<br />


author: Patrik S
body: Hello [@Mustafa ahmed](/t5/user/viewprofilepage/user-id/5117636) ,

The error you reported is happening because the **plutil**tool that you use in the script is not installed in the docker image you are using in your step. \\

The steps in bitbucket pipelines run in a Linux-based docker container. The **plutil**is a MacOS tool and is not available for Linux.

However, it seems there's a different command in Linux called **plistutil** that provides similar functionality. In order to use **plistutil** in your build step you will have to first install it before running the script, as in the below example :

```
pipelines:

 custom:
   new_publish:
    - step:
        name: new publish
        script:
           - echo "This step runs once you click the 'Run' button"
           - apt-get update && apt-get install -y libplist-utils # installing the package that contains plistutil
           - /bin/sh Build_script.sh
           - echo "git commands"
           - git add .
           - git commit -m "change 122"
```

We have added the command to install the package libplist-utils, which contains the command **plistutil.**

Then, you will need to edit the content of Build_script.sh and replace the **plutil** command with **plistutil**.

Since plistutil is a different command, it might have different options available, so I would recommend taking a look at its official manual :

* <https://manpages.debian.org/testing/libplist-utils/plistutil.1.en.html>

Thank you, [@Mustafa ahmed](/t5/user/viewprofilepage/user-id/5117636) !

Patrik S


author: Mustafa ahmed
body: Hello [@Patrik S](/t5/user/viewprofilepage/user-id/4603309)   

You really helped me to understand the missing parts, I appreciate your support.  

My last beginner question:  

I have changed my Build_script.sh to:  

```
API_URL="www.production.com"

APP_CONSTANT_FILE=AppConstant.cs

if [ -e "$APP_CONSTANT_FILE" ]
then
echo "Updating AppConstant"
sed -i 's#ApiUrl = "[-A-Za-z0-9:_./]*"#ApiUrl = "'$API_URL'"#' $APP_CONSTANT_FILE
fi
```

and the pipeline run and was completed successfully.  

![Screenshot 2023-01-27 at 1.06.31 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/236763iAADEC87EBB634F7E/image-size/large?v=v2&px=999 "Screenshot 2023-01-27 at 1.06.31 AM.png")  

but I didn't find that change in my source code or that commit in my repository commits  

what I am missing here?


author: Mustafa ahmed
body: Hi [@Patrik S](/t5/user/viewprofilepage/user-id/4603309)   

I was missing the push command   

It works now thanks.


Tags: atl-gruland

bitbucket-cloud

cloud