unclassified:datadogGlobalConfiguration:datadogClientConfiguration:# Select the `Datadog Agent` modedatadogAgentConfiguration:# Configure Datadog Agent hostagentHost:'<your-agent-host>'# Configure Datadog Agent portagentPort:8125# (Optional) Configure logs collection port as configured in your Datadog AgentagentLogCollectionPort:10518# Configure traces collection portagentTraceCollectionPort:8126# Enable CI Visibility flagenableCiVisibility:true# (Optional) Configure your CI Instance nameciInstanceName:'jenkins'# (Optional) Configure the name of the host that you use to access Datadog UIdatadogAppHostname:'app.datadoghq.com'# (Optional) Enable Logs StoragecollectBuildLogs:true
Jenkins インスタンスの Web インターフェースで、[Manage Jenkins] > [Configuration as Code] に移動します。
unclassified:datadogGlobalConfiguration:datadogClientConfiguration:# Select the `Agentless` mode (using API key).datadogApiConfiguration:intake:datadogIntakeSite:# Configure your Datadog sitesite:''apiKey:datadogCredentialsApiKey:# Configure ID of Jenkins credentials that store your API keycredentialsId:'my-api-key-credentials-id'# Enable CI Visibility flagenableCiVisibility:true# (Optional) Configure your CI Instance nameciInstanceName:'jenkins'# (Optional) Configure the name of the host that you use to access Datadog UIdatadogAppHostname:''# (Optional) Enable Logs StoragecollectBuildLogs:true
Jenkins インスタンスの Web インターフェースで、[Manage Jenkins] > [Configuration as Code] に移動します。
Jenkins インスタンスの Web インターフェースで、[Manage Jenkins] > [Script Console] (スクリプトコンソール) に移動します。
コンフィギュレーションスクリプトを実行します。
importjenkins.model.Jenkinsimportorg.datadog.jenkins.plugins.datadog.DatadogGlobalConfigurationimportorg.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfigurationdefjenkins=Jenkins.getInstance()defdatadog=jenkins.getDescriptorByType(DatadogGlobalConfiguration)defagentHost='localhost'// Configure your Datadog Agent host
defagentPort=8125defagentLogCollectionPort=10518// (Optional) Configure logs collection port as configured in your Datadog Agent
defagentTraceCollectionPort=8126// Configure traces collection port
datadog.datadogClientConfiguration=newDatadogAgentConfiguration(agentHost,agentPort,agentLogCollectionPort,agentTraceCollectionPort)datadog.datadogAppHostname='app.datadoghq.com'// the name of the host that you use to access Datadog UI
datadog.enableCiVisibility=truedatadog.collectBuildLogs=true// (Optional) Enable Logs Storage
datadog.ciInstanceName='jenkins'// (Optional) Set your CI Instance name
// Save config
datadog.save()
Agentless (API キーを使用)
Jenkins インスタンスの Web インターフェースで、[Manage Jenkins] > [Script Console] に移動します。
コンフィギュレーションスクリプトを実行します。
importhudson.util.Secretimportjenkins.model.Jenkinsimportorg.datadog.jenkins.plugins.datadog.DatadogGlobalConfigurationimportorg.datadog.jenkins.plugins.datadog.configuration.DatadogApiConfigurationimportorg.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntakeSiteimportorg.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogSiteimportorg.datadog.jenkins.plugins.datadog.configuration.api.key.DatadogTextApiKeydefjenkins=Jenkins.getInstance()defdatadog=jenkins.getDescriptorByType(DatadogGlobalConfiguration)defsite=newDatadogIntakeSite(DatadogSite.)// Pick your Datadog site
defapiKey=newDatadogTextApiKey(Secret.fromString('<YOUR_API_KEY>'))// or `new DatadogCredentialsApiKey('<YOUR_CREDENTIALS_ID>')`
datadog.datadogClientConfiguration=newDatadogApiConfiguration(site,apiKey)datadog.datadogAppHostname=''// the name of the host that you use to access Datadog UI
datadog.enableCiVisibility=truedatadog.collectBuildLogs=true// (Optional) Enable Logs Storage
datadog.ciInstanceName='jenkins'// (Optional) Set your CI Instance name
// Save config
datadog.save()
環境変数を使用する
Datadog Agent を介したレポート (推奨)
Jenkins インスタンスマシンで次の環境変数を設定します。
# Select the Datadog Agent modeDATADOG_JENKINS_PLUGIN_REPORT_WITH=DSD
# Configure the Agent hostDATADOG_JENKINS_PLUGIN_TARGET_HOST=your-agent-host
# Configure the Traces Collection port (default 8126)DATADOG_JENKINS_PLUGIN_TARGET_TRACE_COLLECTION_PORT=8126# Enable CI VisibilityDATADOG_JENKINS_PLUGIN_ENABLE_CI_VISIBILITY=true# (Optional) Configure your CI Instance nameDATADOG_JENKINS_PLUGIN_CI_VISIBILITY_CI_INSTANCE_NAME=jenkins
# (Optional) Configure Log Collection port as configured in your Datadog AgentDATADOG_JENKINS_PLUGIN_TARGET_LOG_COLLECTION_PORT=10518# (Optional) Enable Logs StorageDATADOG_JENKINS_PLUGIN_COLLECT_BUILD_LOGS=true# (Optional) Configure the name of the host that you use to access Datadog UIDATADOG_JENKINS_PLUGIN_DATADOG_APP_HOSTNAME=app.datadoghq.com
Jenkins インスタンスを再起動します。
Agentless (API キーを使用)
Jenkins インスタンスマシンで次の環境変数を設定します。
# Select the Datadog Agent modeDATADOG_JENKINS_PLUGIN_REPORT_WITH=HTTP
# Configure your Datadog siteDATADOG_JENKINS_PLUGIN_DATADOG_SITE=# Configure your API keyDATADOG_JENKINS_PLUGIN_TARGET_API_KEY=your-api-key
# Enable CI VisibilityDATADOG_JENKINS_PLUGIN_ENABLE_CI_VISIBILITY=true# (Optional) Configure your CI Instance nameDATADOG_JENKINS_PLUGIN_CI_VISIBILITY_CI_INSTANCE_NAME=jenkins
# (Optional) Enable Logs StorageDATADOG_JENKINS_PLUGIN_COLLECT_BUILD_LOGS=true# (Optional) Configure the name of the host that you use to access Datadog UIDATADOG_JENKINS_PLUGIN_DATADOG_APP_HOSTNAME=
pipeline{agentanyoptions{datadog(testOptimization:[enabled:true,serviceName:"my-service",// the name of service or library being tested
languages:["JAVA"],// languages that should be instrumented (available options are "JAVA", "JAVASCRIPT", "PYTHON", "DOTNET", "RUBY")
additionalVariables:["my-var":"value"]// additional tracer configuration settings (optional)
])}stages{stage('Example'){steps{echo"Hello world."}}}}
pipeline{agentanystages{stage('Checkout'){steps{script{defgitVars=giturl:'https://github.com/my-org/my-repo.git',branch:'some/feature-branch'// Setting Git information manually via environment variables.
env.DD_GIT_REPOSITORY_URL=gitVars.GIT_URLenv.DD_GIT_BRANCH=gitVars.GIT_BRANCHenv.DD_GIT_COMMIT_SHA=gitVars.GIT_COMMIT}}}stage('Test'){steps{// Execute the rest of the pipeline.
}}}}
パイプラインを含めるまたは除外する
一部のパイプラインを含めるか除外するように Jenkins プラグインを構成できます。
Jenkins インスタンスの Web インターフェースで、[Manage Jenkins] > [Configure System] に移動します。