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 do I make a pre-receive hook for Scriptrunner

Margaria Vince
February 2, 2023

Hello, I am trying to make a pre-hook using Scriptrunner in Bitbucket. The hook is supposed to check if there is a file named "conanfile.py" whenever a user push, if there is not nothing happens but if there is, the hook check what's inside and compare it with a regex I made. The problem I have is that I can't seems to make it find the file. Here is the code of the hook in groovy :

 

def regex = ".*requires\\(\"[^\\d|_|\\-](\\S)+/\\[(\\d)(\\.\\d)*\\]@(eca|exail)/stable\""
def fileName = "conanfile.py"

def file = new File(fileName)

if (file.exists()) {
  file.readLines().each { line ->
    if (line.startsWith("self.requires")) {
      if (!(line =~ regex)) {
        log.error("Lorem Ipsum $line")
        return false
      }
    }
  }
  log.info("All 'self.requires' lines match the regex.")
  return true
} else {
  return true
}

The code compile but it always says that my file is not existing. Anyone got some tips to help me please ?

0 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

TAGS
AUG Leaders

Atlassian Community Events