Jenkins 连接id不是';t在JobTrigger运算符中定义

Jenkins 连接id不是';t在JobTrigger运算符中定义,jenkins,airflow,directed-acyclic-graphs,airflow-operator,Jenkins,Airflow,Directed Acyclic Graphs,Airflow Operator,我想用气流dag在詹金斯做一份工作。我试了以下方法 dag = DAG("test_jenkins", default_args=default_args, schedule_interval=None) job_trigger = JenkinsJobTriggerOperator( dag=dag, task_id="trigger_job", job_name="generate-code-trigger", jenkins_connection_id="

我想用气流dag在詹金斯做一份工作。我试了以下方法

dag = DAG("test_jenkins", default_args=default_args, schedule_interval=None)

job_trigger = JenkinsJobTriggerOperator(
    dag=dag,
    task_id="trigger_job",
    job_name="generate-code-trigger",
    jenkins_connection_id="http://localhost:8080/"  # The connection must be configured first
)

def grab_artifact_from_jenkins(**context):
hook = JenkinsHook("http://localhost:8080/")
jenkins_server = hook.get_jenkins_server()
url = context['task_instance'].xcom_pull(task_ids='trigger_job')
url = url + "code-generator/pom.xml"  # Or any other artifact name
request = Request(url)
response = jenkins_server.jenkins_open(request)
return response  # We store the artifact content in a xcom variable for later use

artifact_grabber = PythonOperator(
    task_id='artifact_grabber',
    provide_context=True,
    python_callable=grab_artifact_from_jenkins,
    dag=dag)

artifact_grabber.set_upstream(job_trigger)
但这给了我一个错误

The conn_id `http://localhost:8080/` isn't defined

这是我第一次使用
JenkinsJobTriggerOperator
。也没有任何有用的例子。如何避免此错误。

您对jenkins\u连接id有误解

jenkins_connection_id="http://localhost:8080/"  # The connection must be configured first
您需要首先通过airflow UI创建与jenkins服务器的正确连接。您现在设置的是一个示例字符串。 它应该是这样的:

jenkins_connection_id="the_connection_id_name_which_you_gave_through_the_ui" 
您可以在此处阅读详细信息:

我尝试了类似的方法,它与bash操作符配合使用

jenkins_iuser_id = Variable.get("jenkins_user_name")
jenkins_pswd = Variable.get("api_token")

cmand_to_exec ='curl -X POST --user ' + jenkins_iuser_id + ':' + jenkins_pswd + ' http://< IP >:8080/job/<JOBNAME>/build '
trigger_cleanup = BashOperator(
        task_id='trigger_jenkins_cleanup_jobs',
        bash_command=cmand_to_exec,
        dag=dag)
trigger_cleanup
jenkins\u iuser\u id=Variable.get(“jenkins\u用户名”)
jenkins_pswd=Variable.get(“api_令牌”)
cmand_to_exec='curl-X POST--user'+jenkins_iuser_id+':“+jenkins_pswd+”http://:8080/job//build”
触发器\u cleanup=bash运算符(
任务\u id='trigger\u jenkins\u cleanup\u jobs',
bash_command=cmand_to_exec,
dag=dag)
触发清除

您是否已经在airflow web ui的“管理-->连接”下设置了连接详细信息?++请确保目标服务器的入站规则允许所有流量!