Zachary Leaf | 28bc001 | 2024-11-05 12:53:48 +0000 | [diff] [blame] | 1 | pipeline { |
| 2 | agent { |
| 3 | label 'docker-amd64-tf-a-jammy' |
| 4 | } |
| 5 | |
| 6 | parameters { |
| 7 | string( |
| 8 | name: 'URL', |
| 9 | defaultValue: 'ssh://review.trustedfirmware.org:29418/TF-A/trusted-firmware-a', |
| 10 | description: 'Repository URL.') |
| 11 | |
| 12 | string( |
| 13 | name: 'REFSPEC', |
| 14 | defaultValue: '+refs/heads/*:refs/remotes/origin/*', |
| 15 | description: 'Git refspec used when fetching.') |
| 16 | |
| 17 | string( |
| 18 | name: 'REFNAME', |
| 19 | defaultValue: 'origin/master', |
| 20 | description: 'Git refname of the last commit to lint.') |
| 21 | |
| 22 | string( |
| 23 | name: 'REFNAME_BASE', |
| 24 | defaultValue: 'origin/master', |
| 25 | description: 'Git refname of the parent of the first commit to lint.') |
| 26 | |
| 27 | credentials( |
| 28 | name: 'SSH_KEY', |
| 29 | description: '', |
| 30 | credentialType: 'com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey', |
| 31 | defaultValue: 'TFA_CI_BOT_USER_SSH_KEY') |
| 32 | } |
| 33 | |
| 34 | stages { |
| 35 | stage('Checkout') { |
| 36 | steps { |
| 37 | withCredentials([sshUserPrivateKey( |
| 38 | credentialsId: params.SSH_KEY, |
| 39 | usernameVariable: 'GERRIT_USER', |
| 40 | keyFileVariable: 'GERRIT_IDENTITY_FILE')]) |
| 41 | { |
| 42 | sh 'mkdir -p ~/.ssh && chmod 0700 ~/.ssh' |
| 43 | sh 'touch ~/.ssh/config && chmod 0600 ~/.ssh/config' |
| 44 | |
| 45 | sh """\ |
| 46 | cat >> ~/.ssh/config <<EOF |
| 47 | Host review.trustedfirmware.org |
| 48 | User ${GERRIT_USER} |
| 49 | IdentityFile ${GERRIT_IDENTITY_FILE} |
| 50 | StrictHostKeyChecking no |
| 51 | PubkeyAcceptedKeyTypes +ssh-rsa |
| 52 | EOF |
| 53 | """.stripIndent() |
| 54 | |
| 55 | checkout([$class: 'GitSCM', |
| 56 | branches: [[name: params.REFNAME]], |
| 57 | userRemoteConfigs: [[ |
| 58 | url: params.URL, |
| 59 | refspec: params.REFSPEC]]]) |
| 60 | |
| 61 | script { |
| 62 | mergeBase = sh( |
| 63 | returnStdout: true, |
| 64 | script: "git merge-base ${params.REFNAME_BASE} HEAD").trim() |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | stage('Lint') { |
| 71 | steps { |
| 72 | script { |
| 73 | if (fileExists('.nvmrc')) { |
| 74 | sh "bash --norc -c 'nvm install'" |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | sh "bash --norc -c 'nvm exec npm ci'" |
| 79 | sh "bash --norc -c 'nvm exec npx commitlint --from=${mergeBase}'" |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |