If you are using gitlab and talking about jenkins pipeline script , you have to create a pipeline job. below is the sample groovy script that you can enhance.
node {
stage ("Checkout"){
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'LocalBranch', localBranch: 'master']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'your_git_cred', url: 'your_gitlab_url']]]
}
stage ("Build and Push to Artifactory"){
tool name: 'Maven3.0', type: 'maven'
sh "mvn clean deploy"
}
}
In the pom , you have to add the artifactory location in the distribution management
<distributionManagement>
<repository>
<id>artifactory</id>
<url>your_artifactory_url</url>
</repository>
<snapshotRepository>
<id>artifactory</id>
<url>your_artifactory_url</url>
</snapshotRepository>
</distributionManagement>
More information about jenkins -pipline
https://jenkins.io/doc/book/pipeline/