{"id":535,"date":"2022-02-16T21:23:33","date_gmt":"2022-02-16T20:23:33","guid":{"rendered":"https:\/\/www.netexpertise.eu\/es\/?p=535"},"modified":"2022-05-07T06:40:43","modified_gmt":"2022-05-07T05:40:43","slug":"registrar-un-esclavo-jenkins-con-api-rest","status":"publish","type":"post","link":"http:\/\/www.netexpertise.eu\/es\/devops\/jenkins\/registrar-un-esclavo-jenkins-con-api-rest.html","title":{"rendered":"Registrar un Esclavo Jenkins con API REST"},"content":{"rendered":"\n<p>Aqu\u00ed se explica c\u00f3mo registrar un nodo <a href=\"\/es\/category\/devops\/jenkins\">Jenkins<\/a> autom\u00e1ticamente con una llamada a una API REST a el maestro.<br>La mayor parte del trabajo consiste en crear el c\u00f3digo json que describe el nuevo esclavo de Jenkins. La configuraci\u00f3n puede ser ligeramente diferente seg\u00fan la configuraci\u00f3n del nodo que desee aplicar.<br>Para obtener exactamente lo que desea, puede crear un esclavo de prueba manualmente y capturar el objeto JSON en la pesta\u00f1a de red de las herramientas de desarrollo de su navegador mientras hace clic en \u00abGuardar\u00bb. Mientras tanto, aqu\u00ed hay un ejemplo, suponiendo que el agente se inicia a trav\u00e9s de un script de inicio:<br><br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"json\" class=\"language-json\">{\n   \"name\": \"my_jenkins_slave\",\n   \"nodeDescription\": \"my Jenkins slave\",\n   \"numExecutors\": \"2\",\n   \"remoteFS\": \"\/home\/jenkins\",\n   \"labelString\": \"slave\",\n   \"mode\": \"EXCLUSIVE\",\n   \"\": [\n      \"hudson.slaves.JNLPLauncher\",\n      \"hudson.slaves.RetentionStrategy$Always\"\n   ],\n   \"launcher\": {\n      \"stapler-class\": \"hudson.slaves.JNLPLauncher\",\n      \"$class\": \"hudson.slaves.JNLPLauncher\",\n      \"workDirSettings\": {\n         \"disabled\": true,\n         \"workDirPath\": \"\",\n         \"internalDir\": \"remoting\",\n         \"failIfWorkDirIsMissing\": false\n      },\n      \"tunnel\": \"\",\n      \"vmargs\": \"\"\n   },\n   \"retentionStrategy\": {\n      \"stapler-class\": \"hudson.slaves.RetentionStrategy$Always\",\n      \"$class\": \"hudson.slaves.RetentionStrategy$Always\"\n   },\n   \"nodeProperties\": {\n      \"stapler-class-bag\": \"true\",\n      \"hudson-slaves-EnvironmentVariablesNodeProperty\": {\n         \"env\": [\n            {\n               \"key\": \"JAVA_HOME\",\n               \"value\": \"\/usr\/lib\/jvm\/java-8-openjdk-amd64\"\n            }\n         ]\n      },\n      \"_comment:\": {\n         \"hudson-tools-ToolLocationNodeProperty\": {\n           \"locations\": [\n               {\n                  \"key\": \"hudson.model.JDK$DescriptorImpl@JAVA-8\",\n                  \"home\": \"\/usr\/bin\/java\"\n               }\n            ]\n         }\n      }\n   }\n}<\/code><\/pre>\n\n\n\n<p><br><br>Todo lo que queda es establecer las siguientes 3 variables de entorno:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">jenkins_user=my_jenkins_slave\njenkins_token=my_jenkins_token\njenkins_url=https:\/\/jenkins.midominio.lan<\/code><\/pre>\n\n\n\n<p><br><br>Y env\u00ede un post del archivo JSON usando una simple solicitud de curl:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ curl -L -s -o \/dev\/null -w \"%{http_code}\" -u $jenkins_user:$jenkins_token \\\n-H \"Content-Type:application\/x-www-form-urlencoded\" -X POST \\\n-d \"json=$(cat \/tmp\/node.json)\" \\\n\"$jenkins_url\/computer\/doCreateItem?name=my_jenkins_slave&amp;type=hudson.slaves.DumbSlave\"; \\\necho\n200<\/code><\/pre>\n\n\n\n<p><br>Si no obtiene un c\u00f3digo de respuesta 200, ejecute el mismo omitiendo \u00ab-o \/dev\/null\u00bb para depurar.<br>Algunos dir\u00e1n que tambi\u00e9n puede usar otras herramientas como Jenkins CLI o plugins, pero la API REST de Jenkins funciona a trav\u00e9s de firewalls y sigue siendo bastante simple de implementar.<br>En el pr\u00f3ximo art\u00edculo, usar\u00e9 este m\u00e9todo para registrar autom\u00e1ticamente un agente de <a href=\"\/es\/devops\/ansible\/registrar-un-esclavo-de-jenkins-con-ansible.html\">Jenkins con Ansible.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Aqu\u00ed se explica c\u00f3mo registrar un nodo Jenkins autom\u00e1ticamente con una llamada a una API REST a el maestro.La mayor parte del trabajo consiste en crear el c\u00f3digo json que describe el nuevo esclavo de Jenkins. La configuraci\u00f3n puede ser ligeramente diferente seg\u00fan la configuraci\u00f3n del nodo que desee aplicar.Para obtener exactamente lo que desea, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[62,64],"tags":[115],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.13 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Netexpertise - Registrar un Esclavo Jenkins con API REST<\/title>\n<meta name=\"description\" content=\"Registre un esclavo de Jenkins utilizando un archivo de configuraci\u00f3n JSON y curl que llame al maestro de Jenkins a trav\u00e9s de una API REST.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.netexpertise.eu\/es\/devops\/jenkins\/registrar-un-esclavo-jenkins-con-api-rest.html\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Netexpertise - Registrar un Esclavo Jenkins con API REST\" \/>\n<meta property=\"og:description\" content=\"Registre un esclavo de Jenkins utilizando un archivo de configuraci\u00f3n JSON y curl que llame al maestro de Jenkins a trav\u00e9s de una API REST.\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.netexpertise.eu\/es\/devops\/jenkins\/registrar-un-esclavo-jenkins-con-api-rest.html\" \/>\n<meta property=\"og:site_name\" content=\"Netexpertise\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-16T20:23:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-05-07T05:40:43+00:00\" \/>\n<meta name=\"author\" content=\"dave\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@netexpertise\" \/>\n<meta name=\"twitter:site\" content=\"@netexpertise\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.netexpertise.eu\/es\/devops\/jenkins\/registrar-un-esclavo-jenkins-con-api-rest.html\",\"url\":\"http:\/\/www.netexpertise.eu\/es\/devops\/jenkins\/registrar-un-esclavo-jenkins-con-api-rest.html\",\"name\":\"Netexpertise - Registrar un Esclavo Jenkins con API REST\",\"isPartOf\":{\"@id\":\"http:\/\/www.netexpertise.eu\/es\/#website\"},\"datePublished\":\"2022-02-16T20:23:33+00:00\",\"dateModified\":\"2022-05-07T05:40:43+00:00\",\"author\":{\"@id\":\"http:\/\/www.netexpertise.eu\/es\/#\/schema\/person\/27ec923be6625ac4b4bb86c8f0b12abf\"},\"description\":\"Registre un esclavo de Jenkins utilizando un archivo de configuraci\u00f3n JSON y curl que llame al maestro de Jenkins a trav\u00e9s de una API REST.\",\"breadcrumb\":{\"@id\":\"http:\/\/www.netexpertise.eu\/es\/devops\/jenkins\/registrar-un-esclavo-jenkins-con-api-rest.html#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.netexpertise.eu\/es\/devops\/jenkins\/registrar-un-esclavo-jenkins-con-api-rest.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.netexpertise.eu\/es\/devops\/jenkins\/registrar-un-esclavo-jenkins-con-api-rest.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Portada\",\"item\":\"http:\/\/www.netexpertise.eu\/es\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Registrar un Esclavo Jenkins con API REST\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.netexpertise.eu\/es\/#website\",\"url\":\"http:\/\/www.netexpertise.eu\/es\/\",\"name\":\"Netexpertise\",\"description\":\"Sistemas \/ Redes \/ DevOps\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.netexpertise.eu\/es\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"es\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.netexpertise.eu\/es\/#\/schema\/person\/27ec923be6625ac4b4bb86c8f0b12abf\",\"name\":\"dave\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"http:\/\/www.netexpertise.eu\/es\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g\",\"caption\":\"dave\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Netexpertise - Registrar un Esclavo Jenkins con API REST","description":"Registre un esclavo de Jenkins utilizando un archivo de configuraci\u00f3n JSON y curl que llame al maestro de Jenkins a trav\u00e9s de una API REST.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.netexpertise.eu\/es\/devops\/jenkins\/registrar-un-esclavo-jenkins-con-api-rest.html","og_locale":"es_ES","og_type":"article","og_title":"Netexpertise - Registrar un Esclavo Jenkins con API REST","og_description":"Registre un esclavo de Jenkins utilizando un archivo de configuraci\u00f3n JSON y curl que llame al maestro de Jenkins a trav\u00e9s de una API REST.","og_url":"http:\/\/www.netexpertise.eu\/es\/devops\/jenkins\/registrar-un-esclavo-jenkins-con-api-rest.html","og_site_name":"Netexpertise","article_published_time":"2022-02-16T20:23:33+00:00","article_modified_time":"2022-05-07T05:40:43+00:00","author":"dave","twitter_card":"summary_large_image","twitter_creator":"@netexpertise","twitter_site":"@netexpertise","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/www.netexpertise.eu\/es\/devops\/jenkins\/registrar-un-esclavo-jenkins-con-api-rest.html","url":"http:\/\/www.netexpertise.eu\/es\/devops\/jenkins\/registrar-un-esclavo-jenkins-con-api-rest.html","name":"Netexpertise - Registrar un Esclavo Jenkins con API REST","isPartOf":{"@id":"http:\/\/www.netexpertise.eu\/es\/#website"},"datePublished":"2022-02-16T20:23:33+00:00","dateModified":"2022-05-07T05:40:43+00:00","author":{"@id":"http:\/\/www.netexpertise.eu\/es\/#\/schema\/person\/27ec923be6625ac4b4bb86c8f0b12abf"},"description":"Registre un esclavo de Jenkins utilizando un archivo de configuraci\u00f3n JSON y curl que llame al maestro de Jenkins a trav\u00e9s de una API REST.","breadcrumb":{"@id":"http:\/\/www.netexpertise.eu\/es\/devops\/jenkins\/registrar-un-esclavo-jenkins-con-api-rest.html#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.netexpertise.eu\/es\/devops\/jenkins\/registrar-un-esclavo-jenkins-con-api-rest.html"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.netexpertise.eu\/es\/devops\/jenkins\/registrar-un-esclavo-jenkins-con-api-rest.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Portada","item":"http:\/\/www.netexpertise.eu\/es"},{"@type":"ListItem","position":2,"name":"Registrar un Esclavo Jenkins con API REST"}]},{"@type":"WebSite","@id":"http:\/\/www.netexpertise.eu\/es\/#website","url":"http:\/\/www.netexpertise.eu\/es\/","name":"Netexpertise","description":"Sistemas \/ Redes \/ DevOps","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.netexpertise.eu\/es\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"es"},{"@type":"Person","@id":"http:\/\/www.netexpertise.eu\/es\/#\/schema\/person\/27ec923be6625ac4b4bb86c8f0b12abf","name":"dave","image":{"@type":"ImageObject","inLanguage":"es","@id":"http:\/\/www.netexpertise.eu\/es\/#\/schema\/person\/image\/","url":"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g","contentUrl":"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g","caption":"dave"}}]}},"_links":{"self":[{"href":"http:\/\/www.netexpertise.eu\/es\/wp-json\/wp\/v2\/posts\/535"}],"collection":[{"href":"http:\/\/www.netexpertise.eu\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.netexpertise.eu\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.netexpertise.eu\/es\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.netexpertise.eu\/es\/wp-json\/wp\/v2\/comments?post=535"}],"version-history":[{"count":6,"href":"http:\/\/www.netexpertise.eu\/es\/wp-json\/wp\/v2\/posts\/535\/revisions"}],"predecessor-version":[{"id":577,"href":"http:\/\/www.netexpertise.eu\/es\/wp-json\/wp\/v2\/posts\/535\/revisions\/577"}],"wp:attachment":[{"href":"http:\/\/www.netexpertise.eu\/es\/wp-json\/wp\/v2\/media?parent=535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.netexpertise.eu\/es\/wp-json\/wp\/v2\/categories?post=535"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.netexpertise.eu\/es\/wp-json\/wp\/v2\/tags?post=535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}