HTTP

kind: http

sourceconditiontarget

Description

source

The HTML "source" retrieves an information from a HTTP request.

condition

The HTML "condition" tests that an information exist in a HTTP response.

target

The HTML "target" updates a HTTP response.

Parameters

NameTypeDescriptionRequired
requestobject[S][C] Customizes the HTTP request to emit.
    bodystring[S][C] Specifies a custom HTTP request body. Defaults to "" (empty string).
    headersobject[S][C] Specifies custom HTTP request headers. Defaults to an empty map.
    nofollowredirectsboolean[S][C] Specifies whether or not to follow redirects. Default to false (e.g. follow HTTP redirections) unless spec.returnresponseheader is set to true (source only).
    verbstring[S][C] Specifies a custom HTTP request verb. Defaults to “GET”.
responseassertsobject[C] Specifies a set of custom assertions on the HTTP response for the condition.
    headersobject[C] Specifies a set of assertions on the HTTP response headers.
    statuscodeinteger[C] Specifies a custom assertion on the HTTP response status code.
returnresponseheaderstring[S] Specifies the header to return as source value (instead of the body).
urlstring[S][C] Specifies the URL of the HTTP request for this resource.

Example

# updatecli.yaml
name: End to end test of the 'http' resource kind
pipelineid: "e2e/http"

# Sources of type http returns either the body or a header
sources:
  # Returns the content of the 'maven-metadata.xml' file content as source (multi-line, direct HTTP/200)
  getJenkinsWarArtifactMetadatas:
    kind: http
    spec:
      url: https://repo.jenkins-ci.org/releases/org/jenkins-ci/main/jenkins-war/maven-metadata.xml
  # Returns the content of the 'checksums.txt' file content as source (multi-line, following redirections HTTP/3xx)
  getUpdatecli0.65.1Checksums:
    kind: http
    spec:
      url: https://github.com/updatecli/updatecli/releases/download/v0.65.1/checksums.txt # HTTP/302 (GitHub redirection to raw.githubusercontent.com)
  ## Empty Source due to HTTP/3xx not followed (e.g. empty body)
  getUpdatecli0.65.1ChecksumsNoFollow:
    kind: http
    spec:
      url: https://github.com/updatecli/updatecli/releases/download/v0.65.1/checksums.txt # HTTP/302 (GitHub redirection to raw.githubusercontent.com)
      request:
        nofollowredirects: true # Default is false
  # Returns the content of the Header 'Location' (e.g. the target of the HTTP redirect)
  getRedirectLocationForUpdatecliLinuxAmd64Archive:
    kind: http
    spec:
      url: https://github.com/updatecli/updatecli/releases/download/v0.65.1/updatecli_Linux_arm64.tar.gz
      returnresponseheader: Location
  # Returns the content of the 'maven-metadata.xml' file from the private URL (custom headers for the request)
  getWithCustomRequest:
    kind: http
    spec:
      url: https://repo.jenkins-ci.org/releases/org/jenkins-ci/main/jenkins-war/maven-metadata.xml
      request:
        headers:
          Authorization: 'Bearer Token'
          Accept: 'application/xml'
        verb: GET 
  ## Source fails with an error: the URL returns HTTP/404 (same for server-side errors such as HTTP/5xx)
  # failOnHttpError:
  #   kind: http
  #   spec:
  #     url: https://google.com/do-not-exist


conditions:
  # Returns 'true' if the specified URL returns HTTP/1xx, HTTP/2xx or HTTP/3xx
  checkForURL:
    kind: http
    sourceid: getJenkinsWarArtifactMetadatas
    spec:
      url: https://repo.jenkins-ci.org/releases/org/jenkins-ci/main/jenkins-war/maven-metadata.xml
  ## Conditions returns 'false' as the URL returns HTTP/404
  ## If there is an HTTP/500 (server side error) then the conditions fails with an ERROR (different than returning false which "skips" the pipeline)
  # checkForNonExistingUrl:
  #   kind: http
  #   sourceid: getJenkinsWarArtifactMetadatas
  #   spec:
  #     url: https://google.com/do-not-exist
  # Returns 'true' if the specified URL returns HTTP/1xx, HTTP/2xx or HTTP/3xx to the custom request (custom verb and headers)
  checkWithCustomRequest:
    kind: http
    sourceid: getJenkinsWarArtifactMetadatas
    spec:
      url: https://repo.jenkins-ci.org/releases/org/jenkins-ci/main/jenkins-war/maven-metadata.xml
      request:
        headers:
          Authorization: 'Bearer Token'
          Accept: 'application/xml'
        verb: HEAD
  # Returns 'true' if the response code is HTTP/302 and has header "Content-Type" set to "application/xhtml"
  getUpdatecli0.65.1Checksums:
    kind: http
    sourceid: getJenkinsWarArtifactMetadatas
    spec:
      url: https://github.com/updatecli/updatecli/releases/download/v0.65.1/checksums.txt # HTTP/302 (GitHub redirection to raw.githubusercontent.com)
      responseasserts:
        statuscode: 302 
        headers:
          Content-Type: "text/html; charset=utf-8"

Important

Most of the Updatecli plugins that manipulate files can usually specify the http scheme in the file path to retrieve the file from a remote location to be used in a source or a condition. But the HTTP plugin is designed to provide more flexibility when working with HTTP requests via additional settings like custom headers, or custom http verbs. Also worth mentioning the http plugin also works for targets.

# updatecli.yaml
name: Basic Json Example

sources:
  http:
    name: Get value from json
    kind: json
    spec:
      file: https://www.updatecli.io/schema/latest/config.json
      key: $id 
  semverVersion:
    kind: json
    name: Get latest version
    spec:
      file: https://www.updatecli.io/changelogs/updatecli/_index.json
      query: ".Changelogs.[*].Tag"
      versionfilter:
        kind: semver
        pattern: "v0.92.0"

conditions:
  http:
    name: Test value from json
    kind: json
    disablesourceinput: true
    spec:
      file: https://www.updatecli.io/schema/latest/config.json
      key: $schema
      value: http://json-schema.org/draft-04/schema
 
  http-query:
    kind: json
    name: Get latest version
    disablesourceinput: true
    spec:
      file: https://www.updatecli.io/changelogs/updatecli/_index.json
      key: ".Changelogs.(Tag=v0.92.0).PublishedAt"
      value: "2025-01-12 08:14:30 +0000 UTC"

Top