¡Esta es una revisión vieja del documento!
Puedes crear distintas tareas de Jenkins. Los más útiles a día de hoy:
La más fácil para mi hasta ahora es la pipeline pero escogiendo la opción “Pipeline script from SCM” que obtiene el Jenkinsfile de un SCM (SCM = gestor de código tipo Git).
Para crear un pipeline necesitarás un Jenkinsfile, para desarrollarlo tienes los siguientes consejos:
Existen plugins para Docker y para Docker Compose. Para el segundo, por ejemplo, puedes definir un step en el pipeline sintax definiendo un stage: General build step y Docker-compose build step. Con esto podrás parar y detener contenedores y ejecutar comandos en estos. Pero antes tendrás que dar acceso a jenkins a docker, para ello haz los siguientes mapeos si los corres con docker:
ports:
- "8080:8080"
- "50000:50000"
volumes:
- jenkins_vol:/var/jenkins_home
- /home/alfred/PycharmProjects/WgfSeleniumTests:/home:ro
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
There is a Visual Studio Code extension called Jenkins runner: https://marketplace.visualstudio.com/items?itemName=dave-hagedorn.jenkins-runner
Thanks to that extension we will be able to directly run local code into a Jenkins task. However, you will need to previously configure the extension. For that, lets imagine an existent Jenkins pipeline called `testpipeline`. You would open your Visual Studio Code settings file and add the next configuration:
"jenkins-runner.hostConfigs": {
"local": {
"url": "http://127.0.0.1:8080",
"user": "your-jenkins-user",
"password": "your-password"
}
},
"jenkins-runner.jobs": {
"job-testpipeline": {
"isDefault": true,
"runWith": "local",
"name": "testpipeline",
},
}
Locally you would create a Jenkinsfile like this example:
pipeline {
agent any
stages {
stage ('Initialize') {
steps {
echo 'Hello Jenkins!'
}
}
}
}
If we do ctrl+shift+p there will appear a menu where we can select Jenkins runner: Run pipeline script on a default job. Doing that you should see what Jenkins says in the same Visual Studio Code output window.
file:/<direccion repositorio>''