Calling function from another groovy file into Jenkins pipeline

Jenkinsfile

pipeline
{
    agent any
    stages
    {
        stage('build')
        {
            steps
            {
                script
                {
                    //first.groovy path might change as per your need
                    def var1 = load "first.groovy"
                    var1.build("php build")
                }
                sh '''
                echo "build"
                '''
            }
        }
        
        stage('deploy')
        {
            steps
            {
                script
                {
                    def var2 = load "first.groovy"
                    var2.build("php deploy")
                }
                    sh '''
                    echo "deploy"
                    '''
            }
        }
        
        
    }
}

first.groovy

def build(String arg1) {
        sh """
        echo "from build function : ${arg1}"
        """
}

def deploy(String arg2) {
        sh """
        echo "from deploy function : ${arg2}"
        """
}

return this

Output:

Running on Jenkins in /var/lib/jenkins/workspace/initedit/ss
[Pipeline] {
[Pipeline] stage
[Pipeline] { (build)
[Pipeline] script
[Pipeline] {
[Pipeline] load
[Pipeline] { (first.groovy)
[Pipeline] }
[Pipeline] // load
[Pipeline] sh
+ echo 'from build function : php build'
from build function : php build
[Pipeline] }
[Pipeline] // script
[Pipeline] sh
+ echo build
build
...........