Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,360,265
Community Members
 
Community Events
168
Community Groups

How to write a scriptRunner script to check for links in the directory in BitBucket

Hi there,

I have the case where a directory that's committed to BitBucket only contain links that's pointing to some of the share in the filesystem.  How can I write a pre-hook script in scriptRunner to check for all the links and make sure those links are from a defined/dedicated location and not from somewhere else that we are not expected?

Thank you for your help.

Kha

1 answer

Hi @Kha Hoang ,

Please can you provide an example use case, to help us answer your question?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Hi Robert,

Let's say I have this set of directory

dir1/dir2/file1.txt

dir1/dir2/file2.txt

dir1/dir2/file3.txt ..............> /root/proj/somefile1.txt

dir1/dir2/file4.txt ..............> /root/proj/subpro/somefile1.txt

dir1/dir2/file5.txt ..............> /mylocal/proj/somefile1.txt

As you see file1 and file2 are real files, file3, 4, and 5 are links some other filesystem

I am expect all the links should come from /root; however, file5.txt is from /mylocal/ and I want a pre-hook to fail/reject the commit so that end-user have to go back to fix it.

Thanks,

Kha

Hi @Kha Hoang ,

If I understand correctly, for example:

/mylocal/proj/somefile1.txt

is the contents of file:

dir1/dir2/file5.txt

And you want to verify the contents "/mylocal/proj/somefile1.txt", is correct? Which in this case, it is not, as the contents should read "/root/proj/somefile1.txt"?

Thanks,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Hi @Robert Giddings _Adaptavist_

Your understanding is exactly right.

Thanks,

Kha

Hi @Kha Hoang ,

OK, great.

The ScriptRunner for Bitbucket team are looking into providing examples regarding file checking, for a range of use cases.

I should have an update in the New Year.

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Hi @Kha Hoang ,

Further to my previous answer, we have now published a Script to our Adaptavist Library that shows an example of blocking commits based on file content.

The Script can be found here: https://library.adaptavist.com/entity/block-commits-for-files-containing-content-that-doesnt-match-regex

Kind regards,

Robert Giddings,

Product Manager,

ScriptRunner for Bitbucket

Thank you very much.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

Apps for Confluence you won't want to miss: RSVP for September's Appy Hours

Calling all collaborators and Confluence users! Our Appy Hours event on September 29th features 4 presenters demoing functionality to superpower Confluence. Don't miss learning about these apps i...

117 views 0 9
Read article

Atlassian Community Events