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

Kha Hoang December 3, 2021

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

0 votes
Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 6, 2021

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

Kha Hoang December 8, 2021

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

Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 20, 2021

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

Kha Hoang December 21, 2021

Hi @Robert Giddings [Adaptavist]

Your understanding is exactly right.

Thanks,

Kha

Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 22, 2021

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

Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 19, 2022

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

Kha Hoang April 22, 2022

Thank you very much.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events