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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events