Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to have pipeline bash script edit a file?

Michael Pietrefesa February 9, 2022

Alright so I created a pipeline that calls a bash script whenever a commit is made to the master branch. In that bash script, I would like to open up a file in the branch that the commit was made to, update a number in it, then commit that new change. How can I go about doing that in a pipeline bash script? I'm not sure if I can have the bash script do a checkout or not. 

1 answer

0 votes
Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 13, 2022

Hi @Michael Pietrefesa,

Thank you for reaching out to the community.

You can definitely run Git commands in your bash script.
When it comes to changing your file on Pipelines, there's no option for you to open a file and edit it while the build is running.
You can, however, automate this process and we usually recommend using the "sed" command.
Sed Linux command will allow you to change a value in a file and save the final output using Git commands.

Here's an example of how to use the Sed command:

- apt-get install -y sed
- sed 's/dev/prod/g' production.env
- your_script_here.bash

(1) You'll need to install it on Pipelines first
(2) Here, I want to change the value "dev" to "prod" in the file production.env
(3) Do save the file changes using Git commands inside the bash script (e.g. Git add, commit, and push). Please also refer to this link for an example of how to push back to your repository.

Here are some relevant resources about Sed command as well:

Hope it helps and let me know how you go with the Sed command.

Regards,
Mark C

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events