|
| 1 | +# How to integrate Jenkins pipeline for Python-selenium on [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=Python-selenium-jenkins) |
| 2 | + |
| 3 | +Jenkins Pipeline is also referred to as "Pipeline" offers a suite of plugins to help integrate your continuous delivery pipeline into Jenkins. Jenkins Pipeline does so with the help of Pipeline DSL(Domain Specific Language) syntax that facilitates easy modelling of even the most complex delivery pipeline. |
| 4 | + |
| 5 | +You can easily create a Jenkins pipeline for Python-selenium automation tests on LambdaTest using the following steps. You can refer to sample test repo [here](https://github.com/LambdaTest/python-selenium-sample). |
| 6 | + |
| 7 | +## Prerequisites For Configuring Jenkins Pipeline With LambdaTest |
| 8 | + |
| 9 | +1. Jenkins 2.X or greater version. |
| 10 | +2. A Jenkins User with root access. |
| 11 | +3. Ensure you have the Pipeline plugin, although, it is displayed under the "suggested plugins" during the post-installation setup of Jenkins. |
| 12 | +4. **LambdaTest Authentication Credentials** |
| 13 | +Be aware of your LambdaTest authentication credentials i.e. your LambdaTest username, access key and HubURL. You need to set them up as your environment variables. You can retrieve them from your **[LambdaTest automation dashboard](https://automation.lambdatest.com/)** by clicking on the key icon near the help button. |
| 14 | + |
| 15 | +- For Linux/Mac: |
| 16 | + |
| 17 | + ``` |
| 18 | + $ export LT_USERNAME= {YOUR_LAMBDATEST_USERNAME}$ export LT_ACCESS_KEY= {YOUR_LAMBDATEST_ACCESS_KEY} |
| 19 | + ``` |
| 20 | + |
| 21 | +- For Windows: |
| 22 | + |
| 23 | + ``` |
| 24 | + $ set LT_USERNAME= {YOUR_LAMBDATEST_USERNAME}$ set LT_ACCESS_KEY= {YOUR_LAMBDATEST_ACCESS_KEY} |
| 25 | + ``` |
| 26 | +## Setting Up Jenkins Pipeline |
| 27 | + |
| 28 | +Find the code for setting up a pipeline for the sample Python-selenium repo. |
| 29 | +```bash |
| 30 | +pipline |
| 31 | +{ |
| 32 | + withEnv(["LT_USERNAME=Your LambdaTest UserName", |
| 33 | + "LT_ACCESS_KEY=Your LambdaTest Access Key", |
| 34 | + "LT_TUNNEL=true"]){ |
| 35 | + |
| 36 | + echo env.LT_USERNAME |
| 37 | + echo env.LT_ACCESS_KEY |
| 38 | + |
| 39 | + stages{ |
| 40 | + stage('setup') { |
| 41 | + |
| 42 | + // Get some code from a GitHub repository |
| 43 | + try{ |
| 44 | + git 'https://github.com/LambdaTest/python-selenium-sample' |
| 45 | + |
| 46 | + //Download Tunnel Binary |
| 47 | + sh "wget https://s3.amazonaws.com/lambda-tunnel/LT_Linux.zip" |
| 48 | + |
| 49 | + //Required if unzip is not installed |
| 50 | + sh 'sudo apt-get install --no-act unzip' |
| 51 | + sh 'unzip -o LT_Linux.zip' |
| 52 | + |
| 53 | + //Starting Tunnel Process |
| 54 | + sh "./LT -user ${env.LT_USERNAME} -key ${env.LT_ACCESS_KEY} &" |
| 55 | + sh "rm -rf LT_Linux.zip" |
| 56 | + } |
| 57 | + catch (err){ |
| 58 | + echo err |
| 59 | + } |
| 60 | + |
| 61 | + } |
| 62 | + stage('build') { |
| 63 | + // Installing Dependencies |
| 64 | + sh 'pip install -r requirements.txt' |
| 65 | + } |
| 66 | + |
| 67 | + stage('test') { |
| 68 | + try{ |
| 69 | + sh 'python lambdatest.py' |
| 70 | + } |
| 71 | + catch (err){ |
| 72 | + echo err |
| 73 | + } |
| 74 | + } |
| 75 | + stage('end') { |
| 76 | + echo "Success" |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +``` |
| 83 | +You can now add this script when creating the pipeline by using the following steps: |
| 84 | + |
| 85 | +1. Create new pipleline |
| 86 | +2. Scroll down to Advanced Project Options. |
| 87 | +3. Paste the Code in the code pane or fetch it via SCM & hit the **Save** button. |
| 88 | + |
| 89 | +**Note:** To run on the tunnel, Either you can use LT_TUNNEL Environment variable to set the tunnelling capability or you can pass in the code. Instructions on the tunnel are are available in the sample repo readme. |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | +# Links: |
| 94 | + |
| 95 | +[LambdaTest Community](http://community.lambdatest.com/) |
| 96 | + |
0 commit comments