The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to have pipeline bash script edit a file?

Deleted user
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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

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 @[deleted],

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

TAGS
AUG Leaders

Atlassian Community Events